Ruby is a dynamic, expressive language used widely for web development, scripting, and automation. On RHEL 8, the system repositories may offer an older Ruby version that does not suit modern projects. rbenv solves this by letting you install and switch between multiple Ruby versions per user without touching system files. This tutorial walks you through installing rbenv, building a specific Ruby version from source, and setting it as your default on RHEL 8.
Prerequisites
- A RHEL 8 server or workstation with a non-root sudo user
- EPEL 8 enabled (
dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm) - Development Tools group installed (
dnf groupinstall -y "Development Tools") - Sufficient disk space (~300 MB) for compiling Ruby from source
Step 1 — Install Build Dependencies
Ruby must be compiled from source by rbenv’s ruby-build plugin, which requires several development libraries.
sudo dnf install -y git gcc make bzip2 openssl-devel readline-devel
zlib-devel libyaml-devel libffi-devel gdbm-devel ncurses-devel
These libraries provide SSL support, a robust readline interface, YAML parsing, and other features that Ruby extensions depend on at compile time.
Step 2 — Clone rbenv into Your Home Directory
rbenv is a shell-level version switcher. Clone it directly from GitHub into ~/.rbenv.
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
Next, clone the ruby-build plugin, which provides the rbenv install command:
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
Step 3 — Add rbenv to Your PATH
Append the following lines to your ~/.bashrc so rbenv is available in every new shell session.
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init - bash)"' >> ~/.bashrc
source ~/.bashrc
Confirm rbenv is in your PATH:
rbenv --version
You should see output such as rbenv 1.3.0.
Step 4 — Install Ruby 3.2.0
List available Ruby versions to confirm what is installable, then install the version you need.
rbenv install --list
This outputs all stable Ruby releases known to ruby-build. Install Ruby 3.2.0:
rbenv install 3.2.0
Compilation typically takes 3–8 minutes. When complete, set this version as your global default:
rbenv global 3.2.0
Verify the active Ruby version:
ruby --version
Expected output: ruby 3.2.0 (2022-12-25 revision a528908271) [x86_64-linux]
Step 5 — Install Bundler
Bundler manages gem dependencies for Ruby projects and is the standard tool used alongside rbenv.
gem install bundler
Run rbenv rehash after installing gems that provide executables so rbenv can expose them on your PATH:
rbenv rehash
bundler --version
Step 6 — Pin a Ruby Version Per Project
rbenv reads a .ruby-version file in the project root to automatically switch to the required Ruby version when you enter that directory. Create one for a project:
mkdir ~/myapp && cd ~/myapp
echo "3.2.0" > .ruby-version
ruby --version
rbenv will now activate Ruby 3.2.0 automatically whenever you are inside ~/myapp, regardless of the global setting. Different projects can therefore require different Ruby versions and rbenv switches transparently.
Conclusion
You have installed all required build dependencies on RHEL 8, cloned rbenv and ruby-build, configured your shell, compiled and installed Ruby 3.2.0, and learned how to pin versions per project using .ruby-version. rbenv’s per-directory version switching makes it easy to work on multiple Ruby projects that require different runtime versions without conflicts. Adding Bundler gives you everything needed to start a modern Ruby application.
Next steps: How to Deploy a Ruby on Rails Application on RHEL 8, How to Install Rust and Cargo on RHEL 8, and How to Install .NET SDK and Runtime on RHEL 8.