Jess Alejo
Posted on August 10, 2024
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
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
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
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
Step 5: Install Ruby
List all available Ruby versions.
rbenv install -l
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
Step 6: Verify the Installation
Check the Ruby version to ensure it was installed correctly.
ruby -v
Step 7: Install Bundler
Install the Bundler gem, which is essential for managing Ruby project dependencies.
gem install bundler
Step 8: Rehash rbenv
Rehash rbenv
to ensure it recognizes the new Ruby installation.
rbenv rehash
Additional Notes
-
Updating rbenv and ruby-build: Occasionally, you might need to update
rbenv
andruby-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
- 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
Following these steps will help you successfully install and manage Ruby versions using rbenv
on your WSL Ubuntu system.
Posted on August 10, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.