WSL for Ruby Development
Developing with Ruby in Windows can be daunting, there are many compatibility issues, the version managers don’t work well, and the console interface can be frustrating depending on which one you use. Luckily Windows has a tool that makes all those pain points go away for the most part, it is Called WSL and in this article, we are going to learn how to set it up to use your Windows machine as a Ruby powerhouse.
WSL is an acronym for Windows Subsystem for Linux, and it is a feature of Windows that allows you to run a Linux environment on your Windows machine without the need for a separate virtual machine or dual booting. WSL is designed to provide a seamless and productive experience for developers who want to use both Windows and Linux at the same time. You can install different distributions of Linux and receive automatic updates straight from the Microsoft store. You also get the full experience with an isolated Linux file system according to the distribution and using bash you can run commands and execute scripts just like you would on a Linux machine.
The default version of WSL that you get when you activate it is WSL2, this version is better than WSL1 since it uses a different technology for virtualization, it has a lighter and more efficient virtual machine to spin up the Linux distribution, and offers 100% compatibility since it uses a full kernel for the machine. But that doesn’t mean that you can’t run WSL1, you can still use it especially when your projects are already set up on WSL1 or your project has very specific requirements, like using serial ports, cross-compilation between Linux and Windows, or very strict memory requirements. For 99% of the projects, you can use WSL2 with no problem.
For installing WSL on your machine you must be running Windows 10 version 2004 and higher (Build 19041 and higher) or Windows 11 and have Hyper-V enabled in your bios. Once you have all these prerequisites you can run the wsl — install command in a powershell window.
This command will enable the features necessary to run WSL and install the Ubuntu distribution of Linux. If you want to change the distribution that it installs you can run it with the following command wsl — install -d <Distribution Name>, just change the distribution name for the one you like that is supported. You can check the supported distributions by running the command wsl –l. If you want to install an unsupported distribution you can follow this guide.
To set a distribution as the default when you use just the wsl command, you have to run wsl -s <DistributionName>, and to run a specific distribution you have to use the command wsl -d <DistributionName>.
Now let’s look at how to use WSL for Ruby development. There are two tools that are essential, the first one is VSCode, to make it work with WSL you just have to install the official WSL extension and connect it with your WSL instance in the bottom left corner of your VSCode editor. That is all that has to be done. After everything is installed you can just type code . to open the VSCode window in the current folder
The second tool is docker and docker desktop, to use it with WSL you must be using version 2. Once the docker desktop is installed in your Windows machine you can go to the configuration and check the Use WSL2 engine box.
That is pretty much all that you need to get started developing with Ruby on Windows, thank you for reading this article and I hope it helped you. If you liked it give it a clap and check out my other articles.
References
- https://learn.microsoft.com/en-us/windows/wsl/install
- https://learn.microsoft.com/en-us/windows/wsl/setup/environment
- https://learn.microsoft.com/en-us/windows/wsl/about
- https://learn.microsoft.com/en-us/windows/wsl/compare-versions
- https://learn.microsoft.com/en-us/windows/wsl/tutorials/wsl-vscode
- https://learn.microsoft.com/en-us/windows/wsl/tutorials/wsl-containers