How to install Ruby on Ubuntu

Endrit Qerreti

Endrit Qerreti

In this tutorial, you will learn how to install Ruby on Ubuntu.

The package that contains Ruby ruby can be found on multiple repositories for different Ubuntu versions.

ruby is listed and available to be downloaded from the universe repository for Ubuntu 20.04 LTS, Ubuntu 22.04 LTS, Ubuntu 23.04 and Ubuntu 23.10

Installing Ruby in any of the mentioned Ubuntu versions above, is easy, and it can be done by using apt package manager.

In this tutorial, we'll be installing Ruby on Ubuntu directly from the terminal by using apt package manager.

Step 1 - Update your system

Whether you are using Ubuntu 20.04, Ubuntu 22.04 , Ubuntu 23.04 or the latest version of Ubuntu 23.10, then you need to update your system before installing Ruby on your machine.

To update the package database in your Ubuntu machine, simply run the command below.

sudo apt update

Step 2 - Install Ruby

Now that the package database is updated, you should be able to use the Universe repository to download Ruby on your system.

To install Ruby on your system, run the following command.

sudo apt install ruby

Step 3 - Verify Ruby Installation

By now Ruby should be installed in your system.

Before your start using Ruby, ensure that Ruby can be launched and that the installation process was completed without errors.

One way to verify that Ruby is working, is by checking Ruby version, by using your terminal.

ruby -v

Step 4 - Use Ruby

You can now use Ruby, and you should be able to integrate Ruby on your projects and run Ruby apps on your Ubuntu machine.

Create a simple Hello world script in Ruby

1) Create Ruby file

You can use any text editor, in this example we are using nano text editor.

sudo nano ruby-project.rb

2) Add Ruby Code

Once ruby-project is created, proceed to add the code below in this file.


puts 'Hello world'

3) Make ruby-project.rb executable

Next, you need to make the Ruby file executable, so you can run it.

chmod +x ruby-project.rb

4) Run ruby-project

All you have to do now is run the Ruby script.

ruby ruby-project.rb

And you should see "Hello, world" output in your terminal.

Uninstall Ruby on Ubuntu

To uninstall Ruby on Ubuntu, you can easily do so by using apt package manager.

To do so, simply run the command below.

sudo apt autoremove ruby --purge

Note: The command above apt autoremove ruby-full --purge will uninstall ruby-full and remove all the dependencies that were installed.


In this tutorial, you learned how to install Ruby, how to run a Ruby script on your machine, and also how to uninstall it on Ubuntu.