How to Install Ruby on Ubuntu 24.04
Ruby is a dynamic, object-oriented programming language perfect for creating basic scripts to complex web applications. To get started, you can install Ruby on Ubuntu 24.04, which offers a modern syntax for productivity, runs with an interpreter instead of a compiler, and provides a wide range of frameworks for various projects.
This article explains how to install Ruby on Ubuntu 24.04 using rbenv and RVM.
rbenv
is a Ruby version manager that allows you to install multiple versions of Ruby and switch between them. Follow the steps below to install Ruby using rbenv.
Install all required dependencies for the
ruby-build
plugin to download and compile Ruby.console$ sudo apt install autoconf patch build-essential rustc libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libgmp-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev libdb-dev libtool uuid-dev
Install the latest rbenv installation script.
console$ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash
Add the rbenv path to the
.bashrc
file.console$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
Reload the
.bashrc
shell configuration to apply the path changes in your active session.console$ source ~/.bashrc
View the installed rbenv version.
console$ rbenv -v
Your output should be similar to the one below.
rbenv 1.3.0-9-gefeab7f
List all available Ruby versions you can install.
console$ rbenv install -l
Note the target Ruby version in your output similar to the one below.
3.1.6 3.2.6 3.3.6 jruby-9.4.9.0 mruby-3.3.0 picoruby-3.0.0 truffleruby-24.1.1 truffleruby+graalvm-24.1.1 Only latest stable releases for each Ruby implementation are shown. Use `rbenv install --list-all' to show all local versions.
Install your target Ruby version. For example,
3.3.6
.console$ rbenv install 3.3.6
The installation process may take
3-5
minutes to complete depending on the available server resources.Set the installed Ruby version as the default if the installation is successful.
console$ rbenv global 3.3.6
View the installed Ruby version.
console$ ruby --version
Your output should be similar to the one below.
ruby 3.3.6 (2024-11-05 revision 75015d4c1f) [x86_64-linux]
Ruby Version Manager (RVM), also known as Ruby environment manager is a command-line tool used to install, manage, and work with multiple Ruby environments on a server. You can use RVM to install Ruby and switch between different Ruby versions.
Install the required GPG keys for RVM.
console$ gpg --keyserver keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
Install RVM.
console$ curl -sSL https://get.rvm.io | bash -s
Load RVM into your shell environment.
console$ source ~/.rvm/scripts/rvm
List and install all the RVM system requirements.
console$ rvm requirements
Enter your sudo user password when prompted to update the server's package index.
Output:
Checking requirements for ubuntu. Installing requirements for ubuntu. ..................... Installing required packages: autoconf, automake, bison, libffi-dev, libgdbm-dev, libsqlite3-dev, libtool, libyaml-dev, sqlite3, libgmp-dev, libncurses-dev, libreadline-dev, libssl-dev............... Requirements installation successful.
View the installed RVM version.
console$ rvm -v
Your output should be similar to the one below.
rvm 1.29.12-next (master) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
List the available Ruby versions you can install.
console$ rvm list known
Note the target Ruby version in your output similar to the one below.
# MRI Rubies [ruby-]1.8.6[-p420] [ruby-]1.8.7[-head] # security released on head [ruby-]1.9.1[-p431] [ruby-]1.9.2[-p330] [ruby-]1.9.3[-p551] [ruby-]2.0.0[-p648] [ruby-]2.1[.10] [ruby-]2.2[.10] [ruby-]2.3[.8] [ruby-]2.4[.10] [ruby-]2.5[.9] [ruby-]2.6[.10] [ruby-]2.7[.8] [ruby-]3.0[.7] [ruby-]3.1[.5] [ruby-]3.2[.6] [ruby-]3[.3.6] [ruby-]3.4[.0-preview1] ruby-head ............
Install a specific Ruby version. For example,
3.3.6
.console$ rvm install 3.3.6
Set the installed Ruby version as the default.
console$ rvm --default use 3.3.6
View all installed Ruby versions.
console$ rvm list
Your output should be similar to the one below.
=* ruby-3.3.6 [ x86_64 ] # => - current # =* - current && default # * - default
Ruby is available in the default APT package manager repositories, but the included version is not the latest. Follow the steps below to install Ruby using the APT package manager.
Update the server's package index.
console$ sudo apt update
Install Ruby.
console$ sudo apt install ruby-full
View the installed Ruby version.
console$ ruby --version
Your output should be similar to the one below.
ruby 3.2.3 (2024-01-18 revision 52bb2ac0a6) [x86_64-linux-gnu]
Uninstall Ruby
Follow the steps below to uninstall a specific Ruby version if necessary on your server.
Uninstall a specific Ruby version using rbenv. For example,
3.3.6
.console$ rbenv uninstall 3.3.6
Remove a specific Ruby version using RVM. For example,
3.3.6
.console$ rvm remove 3.3.6
Uninstall Ruby using APT.
console$ sudo apt autoremove ruby-full
Conclusion
You have installed Ruby on Ubuntu 24.04 using rbenv and RVM. You can use rbenv and RVM to install multiple Ruby versions to run different projects on your server. For more information, visit the following documentation resources: