Install Ruby on Rails on Windows 10 Through WSL

Adam Fleishaker
Jan 18 · 4 min read

Preface

According to the 2020 Ruby on Rails Community Survey, 3% of surveyed Rails community members use Windows. The reason for this is heavily in part that Ruby was developed for Unix-based systems (Linux, macOS), with some key Ruby gems/dependencies/libraries not being optimized or even compatible with Windows out of the box.

Traditional solutions to this problem include the POSIX-providing Cygwin, RubyInstaller, which supports native Windows programs through MSYS2, and more recently, WSL (Windows Subsystem for Linux). See here for a good high-level comparison of Windows options for Ruby development. This tutorial will cover installing WSL.

Note: WSL requires Windows 10, so if you are not on it, you cannot follow this tutorial and would have to use some of the other options outlined above.

Installing WSL

Note: More detailed instructions can be found at Microsoft’s WSL docs here.

Run the following as Administrator in PowerShell to enable WSL:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

Restart your machine, then install Ubuntu from the Microsoft Store. Once installed, open Ubuntu (or invoke wsl in the command prompt) and create your user credentials.

Installing Ruby on Rails

Note: The remainder of this post will follow an abridged version GoRails’ installation guide, credit to them! More detailed instructions can be found at their guide here.

Install the following Ruby dependencies in your newfound Ubuntu environment by running the following:

sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev

You can install Ruby directly or through many different version managers such as rbenv, RVM, and chruby. For our purposes and simplicity’s sake, this tutorial will cover rbenv.

Run the following install commands:

cd
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL

Using rbenv, you can now install a Ruby version, we’ll use 2.7.2:

rbenv install --verbose 2.7.2
rbenv global 2.7.2

rbenv install [your version] installs the Ruby version (--verbose helps track the installation progress), and rbenv global [your version] sets the default Ruby version used by your system.

Please verify that your Ruby is properly installed with the following command:

ruby -v

Install Bundler to manager our gem dependencies by running the following commands:

gem install bundler
rbenv rehash

You’ll likely want to configure GitHub in your environment, to do so:

git config --global user.name [your name]
git config --global user.email "[your email]"
ssh-keygen -t rsa -b 4096 -C "[your email]"
cat ~/.ssh/id_rsa.pub

Paste the contents of your SSH key into your GitHub authorized keys, then check if your Git says you are successfully authenticated with the following command:

ssh -T git@github.com

We’re now ready to install Rails! Run the following commands, which install Rails (we’ll use 6.1.1), NodeJS, and Yarn:

curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
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-get install -y nodejs yarn
gem install rails -v 6.1.1
rbenv rehash

Please verify that your Rails is properly installed with the following command:

rails -v

Finally, you’ll likely want PostgreSQL for your Rails database, install it here and then run the following command to add the gem to support it:

sudo apt install libpq-dev

Bonus (optional): Configure remote WSL Ruby SDK in RubyMine

According to the 2020 Ruby on Rails Community Survey, 15% of surveyed Rails community members use RubyMine as their editor. For help deciding which is best for you, here’s a great article on a few. For our purposes, this bonus will cover RubyMine configuration.

First off, be sure to install RubyMine. Once done and in a project, navigate to Settings → Languages & Frameworks → Ruby SDK and Gems.

Hit the add button (+) → New remote…, and you should be prompted to configure it.

Determine your Ruby version with the following command (2.7.2 if you followed this tutorial):

ruby -v

Select WSL and your Linux distribution (Ubuntu if you followed this tutorial) from the dropdown. For Ruby or version manager path, enter the following, replacing [your version] with your Ruby version and [your Windows username] with the username used for your Windows filesystem:

/home/[your Windows username]/.rbenv/versions/[your version]/bin/ruby

If successful, you should see something like this:

Select the remote Ruby SDK by clicking the radio button. Next, navigate to Tools → Terminal, and replace the Shell path with the following:

wsl.exe

Feel free to name it anything you’d like, such as WSL, and hit OK.

Let’s check our work! Select the Terminal from the bottom of RubyMine. If configured properly, it should open Ubuntu directly rather than Windows command prompt.

If you’ve done so, nice job! 👨‍💻

Postscript

Congratulations! You now have Rails configured on Windows 10 through WSL. 🥳

Special thanks to Microsoft and GoRails’ documentations respectively for the basis of this, which I added context to and simplified where possible.

Wondering where to go next?

The Startup

Get smarter at building your thing. Join The Startup’s +787K followers.

Sign up for Top 10 Stories

By The Startup

Get smarter at building your thing. Subscribe to receive The Startup's top 10 most read stories — delivered straight into your inbox, once a week. Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +787K followers.

Adam Fleishaker

Written by

cs and business @ brandeis university

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +787K followers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store