How to Install Ruby on Ubuntu 24.04


Ruby is an open-source robust programming language that has become famous over the years, especially with the release of the Ruby on Rails framework. Ruby is an object-oriented language that treats everything as an object, making it consistent and elegant. It has many built-in functions and libraries that allow you to work on your projects seamlessly on any system, including Ubuntu 24.04. Ruby is a favorite language for developing web applications, especially the Ruby on Rails framework. Apart from that, Ruby also allows you to automate your tasks and create small utilities with your coding skills.

Follow this blog to learn:

How to Install Ruby on Ubuntu 24.04

You can install Ruby on Ubuntu 24.04 from:

How to Install Ruby on Ubuntu 24.04 from Ubuntu Standard Repository

You can install Ruby on Ubuntu 24.04 directly from the Ubuntu standard repository using the apt install command. However, before installing Ruby from the repository, ensure packages are updated in the repository. Simply running the following command will install the package updates if available on your system.

sudo apt update && sudo apt upgrade -y

Once updating the standard repository, install Ruby on Ubuntu from the following command:

sudo apt install ruby-full -y

To confirm the Ruby installation on Ubuntu from the standard system repository, you can use the following command:

ruby --version

Note: To completely remove Ruby from Ubuntu installed through the repository method, use the following command:

sudo apt autoremove ruby-full -y

How to Install Ruby on Ubuntu 24.04 from Ruby Version Manager

You can also install Ruby on Ubuntu 24.04 from the Ruby Version Manager (RVM). The RVM is a software package for installing and managing multiple Ruby versions on your system. The advantage of using this method is that you can install any Ruby version and quickly switch to a version of your choice through a single command.

To install Ruby on Ubuntu 24.04 from RVM, follow the below-given steps:

Step 1: Add GPG Key

First, add the GPG key for authenticating the RVM installation on Ubuntu, you can do this by using the following command:

gpg --keyserver keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

Step 2: Install RVM Stable Version on Ubuntu

Then install the RVM stable version on the Ubuntu system through the following curl command:

curl -sSL https://get.rvm.io | bash -s stable

Note: If a curl command not found error occurs, install the curl command utility on Ubuntu using the following command:

sudo apt install curl -y

Then execute the above curl command again to perform the installation.

Step 3: Save the Changes

To save the changes and start using RVM on Ubuntu, run the following source command by changing the username accordingly:

source /home/username/.rvm/scripts/rvm

Alternatively, you can also restart the terminal in case you don’t want to execute the source command.

Step 4: Check for Ruby Versions on Ubuntu

To check for different Ruby versions that can be installed on Ubuntu through RVM, use the following command:

rvm list known

Step 5: Install Ruby on Ubuntu from RVM

To install any Ruby version on Ubuntu through RVM, simply use the following syntax:

rvm install rubu-version_no

Replace the version_no with the Ruby version you want to install on Ubuntu through RVM. Here, we are installing the Ruby latest version that is 3.3.0 at the time of installation using the following command:

rvm install rubu-3.3.0

Step 5: Confirm Ruby Installation

To confirm, that Ruby is successfully installed through RVM on Ubuntu, you can use the following command:

ruby --version

Note: To uninstall a specific version of Ruby, you can use the following syntax:

rvm uninstall ruby-version_no

Note: If you have installed multiple Ruby versions on Ubuntu through rvm, you can use the specific Ruby version by setting it as the default one using:

rvm use version_no --default

How to Install Ruby on Ubuntu 24.04 from rbenv

rbenv is a command-line utility that you can use to install and manage multiple Ruby versions on your system. To perform the Ruby installation on Ubuntu 24.04 from rbenv, follow the below-given steps:

Step 1: Install rbenv on Ubuntu

First, install the rbenv package on Ubuntu from the default repository using the following command:

sudo apt install rbenv -y

Step 2: Get a List of Ruby Versions from Rbenv

Now, use the following command to get the list of stable Ruby versions that can be installed on Ubuntu through rbenv:

rbenv install --list

To show all local versions of Ruby that you can install through rbenv, use the following command:

rbenv install --list / -L

Step 3: Install Ruby on Ubuntu from rbenv

To install a specific Ruby version on Ubuntu from rbenv, you can use the following syntax:

rbenv install version

Here, we are installing the Ruby version 3.1.2 on Ubuntu from rbenv using the following command:

rbenv install 3.1.2

Step 4: Confirm the Ruby Installation

To confirm the correct version of Ruby is installed through rbenv, you can use the following command:

ruby --version

Note: To uninstall a specific Ruby version from Ubuntu installed through rbenv, you can use the uninstall command followed by the version_no you want to remove.

rbenv uninstall version_no

How to Install Ruby on Ubuntu 24.04 from Snap Store

You can also use the Snap Store to install Ruby on Ubuntu 24.04. Snap Store is an external package manager preinstalled on the Ubuntu system that installs and manages missing packages from the official system repository. Use the below-given steps to install Ruby on Ubuntu 24.04 from the Snap Store:

sudo snap install ruby --classic

To confirm the Ruby installation on Ubuntu through Snap Store, you can use the following command:

ruby --version

Note: To remove Ruby from Ubuntu installed through Snap Store, you can use the below-given command:

sudo snap remove ruby

Bonus Method: How to Install Ruby on Rails on Ubuntu 24.04

Ruby on Rails is a web application framework that relies on Ruby programming language to function on your system. By using Ruby on Rails, you can efficiently develop your applications from simple to complex. You can install Ruby on Rails on Ubuntu 24.04 from the Rubygems (a package manager) that comes preinstalled with the Ruby package. Follow the below-given gem command to install Ruby on Rails on the Ubuntu system:

sudo gem install rails

You can also install Rails on Ubuntu directly from the apt repository using the following command:

sudo apt install rails -y

Note: The rails package will install Rails alongside Ruby on your Ubuntu system.

After installing the Ruby on Rails from the gem package manager, close the terminal and open it again. Then confirm the Rails installation on Ubuntu by using the following command:

rails --version

Conclusion

Ruby is a robust object-oriented programming language used for developing web applications. You can install Ruby on Ubuntu 24.04 from the apt package manager, Ruby version manager, rbenv, and Snap Store. In this blog, we have discussed all these methods for Ruby installation on Ubuntu in detail. It’s totally up to you to choose a method for installing Ruby on Ubuntu. If you want to go with simple installation, you can choose apt package manager and Snap Store methods. However, for installing the latest version of Ruby on Ubuntu, you can go with Ruby version manager or rbenv.

Categories