How to Install Ruby on Ubuntu 24.04

Updated on January 31, 2025
How to Install Ruby on Ubuntu 24.04 header image

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.

Install Ruby Using rbenv

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.

  1. 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
    
  2. Install the latest rbenv installation script.

    console
    $ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash
    
  3. Add the rbenv path to the .bashrc file.

    console
    $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
    
  4. Reload the .bashrc shell configuration to apply the path changes in your active session.

    console
    $ source ~/.bashrc
    
  5. View the installed rbenv version.

    console
    $ rbenv -v
    

    Your output should be similar to the one below.

    rbenv 1.3.0-9-gefeab7f
  6. 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.
  7. 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.

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

    console
    $ rbenv global 3.3.6
    
  9. 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]

Uninstall Ruby

Follow the steps below to uninstall a specific Ruby version if necessary on your server.

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

    console
    $ rbenv uninstall 3.3.6
    
  2. Remove a specific Ruby version using RVM. For example, 3.3.6.

    console
    $ rvm remove 3.3.6
    
  3. 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: