Moving Rails Development to Windows WSL 2 Linux

November 3, 2019


New Opportunity: Linux on Windows via WSL 2

With the now general availability of WSL 2 on Windows 10, it has now become possible to run Linux desktop on a Windows PC without the need of a Virtual Machine. WSL 2 is the 2nd iteration of the Windows Subsystem for Linux, this time with a Linux kernel. We can already utilize WSL 1 with the availability of Bash shell which is vastly superior to the command window (Cmd).

For further details on:

  • Why you would want Lynux
  • Why not use a Virtual Machine
  • How is WSL 2 different, eg speed
  • What new things you will be able to do, eg docker

see https://www.makeuseof.com/tag/windows-linux-kernel/

and https://www.theverge.com/2019/5/6/18534687/microsoft-windows-10-linux-kernel-feature

But I can already build and run my Rails app on Windows

Simple Rails applications can be built and run on Windows 10, however as we have found, there may come a point when you will need to introduce a new feature with a gem that that is not compatible with Windows. For example adding websockets was our tipping point for [Moving Rails development from Windows to Linux] (/post/moving-rails-development-from-windows-to-linux/).

Plus it is nice to be in an environment more like the deployment environment, Linux on AWS in our case.

How to move to Linux on Windows via WSL 2 (The “Plan”)

WSL 2 is here! If you are running Windows 10, updated to version 2004, Build 19041 or higher: you are good to go. Install the Windows Subsystem for Linux by following these instructions: https://docs.microsoft.com/en-us/windows/wsl/install-win10

Maybe this is worth looking at: https://www.hanselman.com/blog/RubyOnRailsOnWindowsIsNotJustPossibleItsFabulousUsingWSL2AndVSCode.aspx

2020.07.26: Graphic / GUI programs wont run on WSL 2

If you were hoping to have the whole linux desktop and range of GUI applications, WSL 2 doesnt support this yet. For example trying to run Geany WSL 2:

$ geany
Unable to init server: Could not connect: Connection refused
Geany: cannot open display

So your options are

  1. buy x410.dev or similar from microsoft store to run GUI applications on WSL 2
  2. Stick with currently available Windows GUI applications.
  3. Ditto but retool to use VS code if you arent already. VS code has good support for WSL 2

The detailed steps we took to get WSL 2 up and running for a Rails development environment are here:

[How We Moved Rails Development to Windows WSL2 Linux] (/post/how-we-moved-rails-development-to-windows-wsl2-linux/).

Note: You can access your WSL 2 folders from windows like this:

$ \\wsl$

and the other way from WSL 2 to Windows:

$ /mnt/c

GUI app support is in the pipeline for WSL 2: https://www.omgubuntu.co.uk/2020/05/run-linux-apps-on-windows-10-wsl-2

© 2020 Keith P | Follow on Twitter | Git