DEV Community

Cover image for Installing Ruby using rbenv on your WSL Ubuntu system
Jess Alejo
Jess Alejo

Posted on

Installing Ruby using rbenv on your WSL Ubuntu system

Installing Ruby using rbenv on your WSL Ubuntu system is a great way to manage multiple Ruby versions. Below are the step-by-step instructions:

Step 1: Update Your Package List

First, ensure your package list is up to date.

sudo apt update
Enter fullscreen mode Exit fullscreen mode

Step 2: Install Dependencies

Install the necessary dependencies for rbenv and Ruby.

sudo apt install -y build-essential libssl-dev libreadline-dev zlib1g-dev libffi-dev libyaml-dev

Enter fullscreen mode Exit fullscreen mode

Step 3: Install rbenv

Clone the rbenv repository from GitHub and add it to your shell.

git clone https://github.com/rbenv/rbenv.git ~/.rbenv
~/.rbenv/bin/rbenv init
Enter fullscreen mode Exit fullscreen mode

Step 4: Install ruby-build

Clone the ruby-build repository into the rbenv plugins directory.

git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
Enter fullscreen mode Exit fullscreen mode

Step 5: Install Ruby

List all available Ruby versions.

rbenv install -l
Enter fullscreen mode Exit fullscreen mode

Install your desired Ruby version (replace 3.3.4 with the version you want to install).

rbenv install 3.3.4
rbenv global 3.3.4 # to activate this Ruby version as the new default
Enter fullscreen mode Exit fullscreen mode

Step 6: Verify the Installation

Check the Ruby version to ensure it was installed correctly.

ruby -v
Enter fullscreen mode Exit fullscreen mode

Step 7: Install Bundler

Install the Bundler gem, which is essential for managing Ruby project dependencies.

gem install bundler
Enter fullscreen mode Exit fullscreen mode

Step 8: Rehash rbenv

Rehash rbenv to ensure it recognizes the new Ruby installation.

rbenv rehash
Enter fullscreen mode Exit fullscreen mode

Additional Notes

  • Updating rbenv and ruby-build: Occasionally, you might need to update rbenv and ruby-build. You can do this by navigating to their respective directories and pulling the latest changes from GitHub:
cd ~/.rbenv
git pull
cd ~/.rbenv/plugins/ruby-build
git pull
Enter fullscreen mode Exit fullscreen mode
  • Switching Ruby Versions: To switch Ruby versions, simply install the desired version and set it globally or locally for a specific project:
rbenv install x.x.x
rbenv global x.x.x  # For system-wide
# or
rbenv local x.x.x   # For a specific project
Enter fullscreen mode Exit fullscreen mode

Following these steps will help you successfully install and manage Ruby versions using rbenv on your WSL Ubuntu system.

Top comments (1)

Collapse
 
fasakinhenry profile image
Fasakin Henry

Thanks for this