Time for a new dev environment for home/hobby.
Environment: Windows 11 Home, Windows Subsystem for Linux, Ubuntu 20.04, ruby 3.1.2, rails 7.3.0.1
This time, I decide not to use a usual virtualization layer like OracleVM VirtualBox or VMworkstation, instead I give a try to the Windows Subsystem for Linux: WSL. Using WSL defaults to a Ubuntu install, which is fine.
The installation will require 7 steps
- Install WSL and Ubuntu
- Get rbenv
- Install ruby-build as a rbenv plugin
- Build ruby
- Add the bundler gem
- Add sqlite
- Install rails
1. Install WSL and Ubuntu
Open a PowerShell command prompt as admin:
$ wsl --install

Then reboot your laptop, the “Ubuntu on Windows” is automatically started and prompts for a user/password:

No Ubuntu update is available, but if some updates are available the command to install them is shown, simple and well known:
$ sudo apt update
2. Get rbenv
$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
$ echo 'eval "$(rbenv init - bash)"' >> ~/.bashrc
$ exec $SHELL
Note
Since I have installed manually rbenv from git, the way to keep it up to date will be:
$ cd ~/.rbenv; git pull; cd -
3. Install ruby-build as a rbenv plugin
$ mkdir -p "$(rbenv root)"/plugins
$ git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
You can check the installation of rbenv and ruby-build using the rbenv-doctor script:
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/main/bin/rbenv-doctor | bash
4. Build ruby
First, I need to add some packages to my Ubuntu system:
$ sudo apt-get install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev libdb-dev uuid-dev
Then build a version of ruby, you can display a list of avaible stable ruby releases:
rbenv install -l
2.6.10
2.7.6
3.0.4
3.1.2
...
Only latest stable releases for each Ruby implementation are shown
...
I decide to go for the latest 3.1.2 that was released in April 2022:
$ rbenv install 3.1.2
The ruby interpreter installs in a subdirectory of ~/.rbenv:

I set this installation as the default version:
$ rbenv global 3.1.2
Then I can check my ruby installation and version using ‘ruby -v’:
$ ruby -v
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]
5. Add the bundler gem
The ruby language is augmented by some modules that are named “gems”. gem is also the name of a binary tool that is installed along with ruby and allows to basically add/list/remove/update the gems. Managing the gem requirements of a rails app can be a tedious task. Bundler is a gem that will automatically install the correct gems in the expected versions, it enforces the gem dependencies of the app. Rails is a collection of Ruby gems, which requires the help of bundler to be properly installed.
Bundler gem installation is as simple as:
$ gem install bundler
6. Add sqlite
I need a database server for my rails application. For the purpose of development, sqlite is the easiest and lightest option. Ubuntu does not ship with sqlite installed, it is recommended to add it before the installation of rails:
$ sudo apt install sqlite3
SQLite Browser would be a nice addition to the development environment, unfortunately it is not available in WSL. I don’t understand why as WSL is able to display some graphic Linux apps but I didn’t dig the question.
Update: Nov. 16, 2023
At the time of writing this post, Aug. 12, 2022, there was no way to run SQLite Browser in WSL but now there is a workaroud using WSLg, check SQLite Browser fails to open a DB inside a wsl2 installation
Let’s add the SQLite library anyway that can be useful for future gems:
$ sudo apt install libsqlite3-dev
Production environments will require a more powerful database software like postgresql for instance.
7. Install rails
It it not required anymore to specify the target version of your rails setup after the -v switch, instead you can just type:
$ gem install rails
This will add 35 new gems, rails being the last one of them. Additionally, the documentation for these gems is being generated and indexed. Check your rails installation by displaying its version number:
$ rails -v
Rails 7.0.3.1
Now, I have everything in order to create a rails application. I point your preferred text/code editor to \\WSL$\Ubuntu\home. The required gems will be added when I create my app using rails new <app-name>.
Useful references:
- Microsoft guide for Windows Subsystem for Linux:
https://learn.microsoft.com/en-us/windows/wsl/setup/environment - A good guide by DigitalOcean hosting company:
https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rbenv-on-ubuntu-20-04 - Another good tutorial from the Techiediaries website:
https://www.techiediaries.com/install-ruby-2-7-rails-6-ubuntu-20-04/ - The official installation guide for rbenv:
https://github.com/rbenv/rbenv#basic-github-checkout - The official documentation for ruby-build including the build environment:
https://github.com/rbenv/ruby-build/wiki
https://github.com/rbenv/ruby-build#readme - Ruby gems basics
https://guides.rubygems.org/rubygems-basics/ - Getting started with Rails
https://guides.rubyonrails.org/getting_started.html - Gorails.com provides a Rails learning course and some installation guides for Ubuntu macOS and Windows including git configuration:
https://gorails.com/setup/windows/10 - Sublime Text is a perfect source code text editor for Rails. For those who know and enjoy the vi/vim Unix/Linux text editor, Sublime Text provides a vi mode called “Vintage” that is easy to activate:
https://www.sublimetext.com/docs/vintage.html