Tuesday, September 29, 2020

Ruby on Rails development on Windows 10

I have a Surface running Windows 10 that I decided to use for development work. As it turned out, Windows now has a Windows Subsystem for Linux (WSL) that provides a Linux environment. 

I tried out WSL 1 initially and liked it. I thought this was Linux running inside a VM though it turns out that there was no real Linux kernel involved. WSL1 runs "unmodified Linux ELF64 binaries by virtualizing a Linux kernel interface on top of the Windows NT kernel". Windows Subsystem For Linux Overview has a lot of the details.

WSL2 was recently released which does run a full Linux kernel using Hyper-V. Having decided to use the Surface to try out React + Rails, I did the following to set things up.

  1.  Follow WSL installation guide to install WSL1 
    dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestartdism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
    
  2. Once WSL2 update was available, install the update and then follow the above guide to update to WSL 2
    dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
  3. Install the Linux kernel update specified in the guide.
  4. Install Ubuntu from Microsoft Store.
  5. Install packages needed for rails:
    sudo apt install ruby-dev gcc zlib1g zlib1g-dev make sqlite3 postgresql
    
  6. Install rails
    sudo gem install rails
    
  7. Try to create a new project - RoR has errors for various dependencies. So install packages needed for rails to create a new project
    sudo apt install ruby-bundler g++ libsqlite3-dev nodejs npm yarn
    
  8. Creating a new project still fails with an error on yarn version (ArgumentError: Malformed version number string 0.32+git). Follow their instructions to install the latest version of yarn.
    sudo apt remove yarn
    
    curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
    echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
    
    sudo apt update && sudo apt install yarn
  9. Finally create a new rails project with react
    rails new react-project --webpack=react

Ruby on Rails development on Windows 10

I have a Surface running Windows 10 that I decided to use for development work. As it turned out, Windows now has a Windows Subsystem for Li...