How to Install rbenv on Ubuntu or Debian-based System
Seamlessly manage your appβs Ruby environment: A Step-by-Step Guide to Installing rbenv π»
If youβre a Ruby developer, you know how important it is to have a version manager that allows you to switch between different versions of Ruby. rbenv
is a popular version manager for Ruby that makes it easy to install, manage, and switch between different versions of Ruby on your Unix-based system. In this tutorial, weβll go through the steps of installing rbenv
on your system. π
Prerequisites π§
Before we start, ensure your system has the necessary dependencies installed. On Ubuntu or Debian, you can use the following command to install them:
sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev libffi-dev
On other systems, you may need to use a different package manager or install the dependencies manually.
Step 1: Install rbenv
π‘
The first step is to clone the rbenv
repository from GitHub into your home directory:
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
Step 2: Configure your shell to load rbenv
π¨βπ»
The following commands should automatically load rbenv
when you start your terminal.
For bash:
echo 'eval "$(~/.rbenv/bin/rbenv init - bash)"' >> ~/.bashrc
For Zsh:
echo 'eval "$(~/.rbenv/bin/rbenv init - zsh)"' >> ~/.zshrc
For Fish shell:
echo 'status --is-interactive; and ~/.rbenv/bin/rbenv init - fish | source' >> ~/.config/fish/config.fish
Step 3: Reload your shell configuration π€
After you've added the lines to your shell configuration file, you need to reload your shell configuration. Run the following command to reload your shell configuration:
source ~/.bashrc
or
source ~/.zshrc
or for Fish shell:
source ~/.config/fish/config.fish
Step 4: Verify that rbenv
is installed π»
To make sure that rbenv
is installed correctly, run the following command:
rbenv --version
This should print the version of rbenv
that you just installed.
Step 5: Install a Ruby version π
The rbenv install
command is not a part of rbenv
but is provided by the ruby-build plugin.
To install ruby-build
plugin, you can use the following command:
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
Finally, use rbenv
to install a version of Ruby:
rbenv install <version>
Replace <version>
with the version of Ruby that you want to install (such as 2.7.7
). Once the installation is complete, you can set this version as the global default or as the default for a specific project using rbenv global
or rbenv local
, respectively.
Congratulations! π You now have rbenv
installed on your Unix-based system, and now you can easily use it to manage your Ruby versions.