Setting Up a Local WSL Dev Environment For Ruby

Dmitry Sychev
2 min readMar 8, 2021

If you’re anything like me, at some point you may screw up your local environment config so badly that it may need to be nuked from high orbit. You’ll then find yourself in a situation where everything needs to be reinstalled and it’s very unlikely that any of us remember the steps every single time. I’ll be honest, I’m doing this partly as a record for myself to reference whenever I need to reinstall, but at the same time, I hope that anyone else that finds themselves in the same boat will find this useful.

First things first, I prefer to use RBENV to manage my local ruby versions. This makes it easier to jump from project to project that may be using different versions.

sudo apt install rbenvrbenv init

Next up you’ll need to add a few lines to our .bashrc

nano ~/.bashrceval "$(rbenv init -)"

At this point restart your wsl in order for the bash changes to take affect.

wsl.exe --shutdown

Next up you want to install ruby-build in order to actually use the different versions of ruby that are available to RBENV

sudo apt install ruby-buildmkdir -p "$(rbenv root)"/pluginsgit clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build

After that, use this to see which versions of ruby are available. If you see the latest version, then everything up to this point was successful.

rbenv install -l

That should be everything for RBENV, next up is NPM and YARN.

sudo apt install npm
sudo npm install -g yarn

Last up is installing postgres.

sudo apt-get install postgresql 
sudo apt-get install libpq-dev

Next up is setting up postgres.

sudo su - postgres
psql

You should end up in the postgres terminal, here’s where you’ll create the user and assign roles.

CREATE ROLE sampleuser WITH SUPERUSER CREATEDB CREATEROLE LOGIN ENCRYPTED PASSWORD '1234';

Lastly, to see if the user and role was created correctly, while still in the psql terminal, run the following command. The last created user should be listed at the top.

/du

That wraps it up. At this point You should be good to go!

--

--