If you are a Ruby developer, you already know the importance of having multiple Ruby versions running on your machine.
Different projects may require different Ruby versions, and switching between them can be a pain if not done correctly.
That’s where rbenv comes into play.
In this blog post, we will walk you through the process of installing Ruby versions using rbenv on your system.
Let’s get started!
What is rbenv?
rbenv is a lightweight Ruby version management tool that lets you quickly switch between different Ruby versions.
It provides a simple and seamless way to manage multiple Ruby environments on your system without causing conflicts or
interfering with your system Ruby.
Installing rbenv
First, you need to install rbenv on your system. You can do this using Homebrew on macOS, Git on Linux or
manually, following the steps below:
macOS
Using Homebrew, run the following command in your terminal:
Linux
Using Git, run the following commands:
git clone https://github.com/rbenv/rbenv.git ~/.rbenv cd ~/.rbenv && src/configure && make -C src echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(rbenv init -)"' >> ~/.bashrc source ~/.bashrc
Manually
Follow the instructions on the official rbenv GitHub page.
Installing ruby-build plugin
Next, you need to install the ruby-build plugin, which provides the rbenv install command.
You can install the plugin using Homebrew on macOS or Git on Linux:
macOS
Using Homebrew, run the following command:
Linux
Using Git, run the following command:
Installing Ruby versions with rbenv
Now that you have rbenv and ruby-build installed, you can start installing Ruby versions.
To see a list of available Ruby versions, run the following command in your terminal:
To install a specific Ruby version, run the following command (replace 2.7.1 with the version you want):
Switching Ruby versions
After the installation is completed, you can switch to the newly installed Ruby version using the following command (replace 2.7.1 with the version you want):
To verify that you are using the correct Ruby version, run:
Conclusion
Now you know how to install Ruby versions with rbenv and switch between them. This tool makes it easy to manage
multiple Ruby environments, allowing you to work on different projects with different Ruby version requirements seamlessly.
Happy coding!