DEV Community

Cover image for Installing Ruby on Ubuntu 24.04
Sanskriti Harmukh for Vultr

Posted on with Aashish Chaurasiya Originally published at docs.vultr.com

Installing Ruby on Ubuntu 24.04

Ruby is a dynamic, object-oriented programming language perfect for creating basic scripts to complex web applications. It 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 guide covers installing Ruby on Ubuntu 24.04 using rbenv, RVM, and APT. By the end, you'll have a working Ruby installation, with the option to manage and switch between multiple Ruby versions on the same server.


Install Ruby Using rbenv

rbenv is a Ruby version manager that lets you install multiple versions of Ruby and switch between them.

1. Install all required dependencies for the ruby-build plugin to download and compile Ruby:

$ 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
Enter fullscreen mode Exit fullscreen mode

2. Install the latest rbenv installation script:

$ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash
Enter fullscreen mode Exit fullscreen mode

3. Add the rbenv path to the .bashrc file:

$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

4. Reload the .bashrc shell configuration to apply the path changes in your active session:

$ source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

5. View the installed rbenv version:

$ rbenv -v
Enter fullscreen mode Exit fullscreen mode

Your output should be similar to the one below:

rbenv 1.3.0-9-gefeab7f
Enter fullscreen mode Exit fullscreen mode

6. List all available Ruby versions you can install:

$ rbenv install -l
Enter fullscreen mode Exit fullscreen mode

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.
Enter fullscreen mode Exit fullscreen mode

7. Install your target Ruby version. For example, 3.3.6:

$ rbenv install 3.3.6
Enter fullscreen mode Exit fullscreen mode

The installation process may take 3-5 minutes to complete depending on the available server resources.

8. Set the installed Ruby version as the default if the installation is successful:

$ rbenv global 3.3.6
Enter fullscreen mode Exit fullscreen mode

9. View the installed Ruby version:

$ ruby --version
Enter fullscreen mode Exit fullscreen mode

Your output should be similar to the one below:

ruby 3.3.6 (2024-11-05 revision 75015d4c1f) [x86_64-linux]
Enter fullscreen mode Exit fullscreen mode

Install Ruby Using RVM

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.

1. Install the required GPG keys for RVM:

$ gpg --keyserver keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
Enter fullscreen mode Exit fullscreen mode

2. Install RVM:

$ curl -sSL https://get.rvm.io | bash -s
Enter fullscreen mode Exit fullscreen mode

3. Load RVM into your shell environment:

$ source ~/.rvm/scripts/rvm
Enter fullscreen mode Exit fullscreen mode

4. List and install all the RVM system requirements:

$ rvm requirements
Enter fullscreen mode Exit fullscreen mode

Enter your sudo user password when prompted to update the server's package index. Your output should be similar to the one below:

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.
Enter fullscreen mode Exit fullscreen mode

5. View the installed RVM version:

$ rvm -v
Enter fullscreen mode Exit fullscreen mode

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]
Enter fullscreen mode Exit fullscreen mode

6. List the available Ruby versions you can install:

$ rvm list known
Enter fullscreen mode Exit fullscreen mode

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
............
Enter fullscreen mode Exit fullscreen mode

7. Install a specific Ruby version. For example, 3.3.6:

$ rvm install 3.3.6
Enter fullscreen mode Exit fullscreen mode

8. Set the installed Ruby version as the default:

$ rvm --default use 3.3.6
Enter fullscreen mode Exit fullscreen mode

9. View all installed Ruby versions:

$ rvm list
Enter fullscreen mode Exit fullscreen mode

Your output should be similar to the one below:

=* ruby-3.3.6 [ x86_64 ]

# => - current
# =* - current && default
#  * - default
Enter fullscreen mode Exit fullscreen mode

Install Ruby Using APT

Ruby is available in the default APT package manager repositories, but the included version is not the latest.

1. Update the server's package index:

$ sudo apt update
Enter fullscreen mode Exit fullscreen mode

2. Install Ruby:

$ sudo apt install ruby-full
Enter fullscreen mode Exit fullscreen mode

3. View the installed Ruby version:

$ ruby --version
Enter fullscreen mode Exit fullscreen mode

Your output should be similar to the one below:

ruby 3.2.3 (2024-01-18 revision 52bb2ac0a6) [x86_64-linux-gnu]
Enter fullscreen mode Exit fullscreen mode

Uninstall Ruby

1. Uninstall a specific Ruby version using rbenv. For example, 3.3.6:

$ rbenv uninstall 3.3.6
Enter fullscreen mode Exit fullscreen mode

2. Remove a specific Ruby version using RVM:

$ rvm remove 3.3.6
Enter fullscreen mode Exit fullscreen mode

3. Uninstall Ruby installed using APT:

$ sudo apt autoremove ruby-full
Enter fullscreen mode Exit fullscreen mode

Next Steps

You now have Ruby installed on Ubuntu 24.04 using rbenv, RVM, and/or APT, with the ability to install and switch between multiple Ruby versions. From here, you can:

  • Install a Ruby framework such as Rails or Sinatra to start building web applications
  • Set a per-project Ruby version with a .ruby-version file when using rbenv or RVM
  • Set up bundler to manage gem dependencies for your projects
  • Review the RVM Documentation or rbenv Manual Page for advanced version management

For the full guide with additional tips, visit the original article on Vultr Docs.

Top comments (0)