Saturday, January 31, 2026

Managing Ruby installations using rbenv and ruby-build

Installing rbenv and ruby-build on Debian-based systems to manage Ruby versions

"rbenv is a version manager tool for the Ruby programming language on Unix-like systems. It is useful for switching between multiple Ruby versions on the same machine and for ensuring that each project you are working on always runs on the correct Ruby version." -- rbenv's README

Introduction

In this article, I will provide steps to install and configure rbenv and ruby-build on a Debian-based Linux system.

Similar to other programming languages(e.g. Python, Perl, and Rust, etc.), I prefer to keep the version of Ruby I use separate from the version installed by my system. This includes any plugins, or packages(in Ruby's case gems). Aside from giving me more granular control, it also helps prevent me from potentially breaking my system by installing an incompatible version of the language.

I've chosen to use rbenv and ruby-build to provide me with a user-controlled environment in which to manage my Ruby installations. There are several other tools(e.g. rvm and asdf that provide similar functionality. My reasoning for selecting rbenv as my tool of choice is simple. I've been using pyenv for several years to manage my Python installations. Pyenv is a direct fork of rbenv, their developers contribute upstream to rbenv and has a familiar command set. Among other features, rbenv provides support for specifying application-specific Ruby versions(via the rbenv local command).

See rbenv's README for additional details on installation and functionality.

For additional information on rbenv, managing gems, or installing Ruby on Rails, take a look a the links provided in the Further Reading section.

Installation

Installing System Prerequisites

Before installing rbenv, we need to ensure that the system has some necessary dependencies installed. From the command line, enter the following commands:


sudo apt update
sudo apt install git curl libssl-dev \
    libreadline-dev zlib1g-dev autoconf \
    bison build-essential libyaml-dev \
    libreadline-dev libncurses5-dev \
    libffi-dev libgdbm-dev libsqlite3-dev

Depending on your system, you may already have some of these packages installed, or you may need to install additional dependencies. The output from sudo apt install should provide additional guidance. system.

Installing rbenv

  1. Clone rbenv into ~/.rbenv.
    • git clone https://github.com/rbenv/rbenv.git ~/.rbenv
  2. Configure your shell to load rbenv when starting the terminal:
    • echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
    • echo 'eval"$(rbenv init - bash)"' >> ~/.bashrc
  3. Reload your shell configuration for changes to take effect. source ~/.bashrc

NOTE: If you are using a shell other than bash, replace ~/.bashrc in the above commands with the appropriate filename(e.g. ~/.zshrc or ~/.config/fish/config.fish)

Installing ruby-build

ruby-build will need to be installed to help compile Ruby binaries. Run the following commands to create a directory for the ruby-build plugin and then download it to the proper directory:


mkdir -p "$(rbenv root)"/plugins
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build

Verifying installation

  1. Check installed version of rbenv

~$rbenv -v (or --version)
rbenv 1.3.2-16-gba96d7e

To check which version of Ruby is installed, use rbenv version(no dashes).

  1. Run rbenv-doctor

The rbenv-doctor script analyzes your system setup for common problems. Run this script to verify that the installation was successful.

curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-doctor | bash

or

wget -q https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-doctor -O- | bash

Either of the commands should produce output similar to the following:


Checking for rbenv shims in PATH: OK
Checking `rbenv install' support: ~/.rbenv/plugins/ruby-build/bin/rbenv-install (ruby-build 20260121)
Counting installed Ruby versions: 1 versions
Auditing installed plugins: OK

For additional troubleshooting assistance, refer to the rbenv wiki

Installing Ruby

With rbenv installed, an updated list of the available Ruby versions can be viewed with the command:


rbenv install -l

#Output

3.2.10
3.3.10
3.4.8
4.0.1
jruby-10.0.2.0
mruby-3.4.0
picoruby-3.0.0
truffleruby-33.0.1
truffleruby+graalvm-33.0.1

Only latest stable releases for each Ruby implementation are shown. Use `rbenv install --list-all' to show all local versions.

As of this writing(20260128), the latest version of Ruby is 4.0.1.


    rbenv install 4.0.1 --verbose

This command should take roughly fifteen minutes to complete. Using the --verbose flag will produce output to the console so that the installation progress can be observed.

Set Default Ruby Version

Once Ruby is installed, set the default version using the global option:


rbenv global 4.0.1

Next, verify that Ruby was properly installed by checking its version number:


ruby --version

#Output

ruby 4.0.1 (2026-01-13 revision e04267a14b) +PRISM [x86_64-linux]

To install and use a different version of Ruby, run the rbenv commands with a different version number, such as rbenv install 3.4.8 and rbenv global 3.4.8.

Removing unneeded Ruby versions

The rbenv uninstall command can be used to remove old versions of Ruby that are no longer needed.


rbenv uninstall 4.0.1

Updating rbenv and ruby-build

Updating rbenv


cd ~/.rbenv
git pull

Updating ruby-build


cd ~/.rbenv
git -C plugins/ruby-build pull

Further Reading

rbenv alternatives

No comments: