I wrote about installing Ruby with rbenv
in a post in my blog, but sharing the useful part here. Note that this is for linux, so some adaptations might be needed.
For those familiar with Python, rbenv
is similar to pyenv
. To install rbenv
, run the following commands:
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
cd ~/.rbenv && src/configure && make -C src
This will download the rbenv
repository to your home directory, and then compile it. Next, add the following lines to your ~/.bashrc
file:
# enable rbenv
if [ -d "$HOME/.rbenv/" ]; then
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init - bash)"
fi
Then, restart your terminal or run . ~/.bashrc
to reload your bash settings. This will make the rbenv
command available in your terminal. To test if this is working properly, run curl -fsSL https://github.com/rbenv/rbenv-installer/raw/main/bin/rbenv-doctor | bash
. It should output something similar to this:
Checking for `rbenv' in PATH: /home/gca/.rbenv/bin/rbenv
Checking for rbenv shims in PATH: Not found
Checking `rbenv install' support: /home/gca/.rbenv/plugins/ruby-build/bin/rbenv-install (ruby-build 20220910.1-10-gecb9d22)
Counting installed Ruby versions: 1 versions
Auditing installed plugins: OK
It will display an error in line Checking for rbenv shims in PATH
. Don’t worry, this will be fixed. Next, you need to install ruby-build as a rbenv
plugin, so you can easily download and install different versions of Ruby. To do so, run the following commands:
mkdir -p "$(rbenv root)"/plugins
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
To check which versions of Ruby are available to install, simply run rbenv install --list
. You can install any version you want, but I recommend installing the latest stable version. At the time of writing, it is version 3.1.2. To install it, you need first to install the ssl dependency and then the Ruby version.
sudo apt install -y libssl-dev
rbenv install 3.1.2