# How to install Ruby on Ubuntu 20.04 and setup programming environment?

{% embed url="<https://youtu.be/mczILWgXt1U>" %}

### Overview

Ruby is a popular programming language used for web development, data analysis, and many other applications. It serves as the basis for Ruby on Rails infrastructure. If you're using Ubuntu, you can install Ruby using the RVM (Ruby Version Manager). This tutorial will guide you throughout the installation process and will create a sample program to check its proper functioning. Here's how to do it:

### **Prerequisites**

There are certain prerequisites that need to be met before you begin:

1\. Server running Ubuntu 20.04

2\. Access to SSH-connected text editor

3\. User account with root or sudo access

4\. Internet connection

### **Key**

· Red box- input.

· Green box- Output.

### **Get Started**

**Step 1: Enter as Root User**

```
sudo -i
```

**Step 2: Update the system**

Begin by updating the system repositories using the following command:

```
sudo apt-get update
```

<img src="https://customer.acecloudhosting.com/index.php?rp=/images/kb/1552_Image1.png" alt="" height="189" width="800">

**Step 3: Install the Dependencies**

Before installing RVM, you need to install the dependencies it requires. Open a terminal window and enter the following command:

```
sudo apt install curl g++ gcc autoconf automake bison libc6-dev libffi-dev libgdbm-dev libncurses5-dev libsqlite3-dev libtool libyaml-dev make pkg-config sqlite3 zlib1g-dev libgmp-dev libreadline-dev libssl-dev
```

<img src="https://customer.acecloudhosting.com/index.php?rp=/images/kb/1553_Image2.png" alt="" height="118" width="800">

You can confirm the installation by typing "Y" and pressing the Enter key when asked.

**Step 4: Installing RVM**

Use the GPG command to access the public key server which will verify the RVM installation releases. This command also provides legitimate sources for downloading the latest RVM releases. To install GPG, use the following command:

```
gpg --keyserver hkp://pgp.mit.edu --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
```

<img src="https://customer.acecloudhosting.com/index.php?rp=/images/kb/1554_Image3.png" alt="" height="222" width="800">

Once you have the dependencies installed, you can install RVM. Enter the following command in your terminal:

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

<img src="https://customer.acecloudhosting.com/index.php?rp=/images/kb/1555_Image4.png" alt="" height="203" width="800">

This command will download and install RVM on your system.

**Step 5: Loading RVM**

Next, you need to load RVM. Enter the following command in your terminal:

```
source ~/.rvm/scripts/rvm
```

<img src="https://customer.acecloudhosting.com/index.php?rp=/images/kb/1556_Image5.png" alt="" height="44" width="800">

This command will load RVM into your shell session.

**Note:** If you get the following error:

```
source ~/.rvm/scripts/rvm
-bash: /root/.rvm/scripts/rvm: No such file or directory
```

<img src="https://customer.acecloudhosting.com/index.php?rp=/images/kb/1557_Image6.png" alt="" height="39" width="800">

You may try using the following command to load rvm files:

```
source /etc/profile.d/rvm.sh
```

<img src="https://customer.acecloudhosting.com/index.php?rp=/images/kb/1558_Image7.png" alt="" height="35" width="800">

**Step 6: Installing Ruby**

Now that RVM is installed and loaded, you can install Ruby by entering the following command in your terminal:

```
rvm install ruby
```

<img src="https://customer.acecloudhosting.com/index.php?rp=/images/kb/1559_Image8.png" alt="" height="97" width="800">

This command will download and install Ruby's latest version. By stating the version number, you can also specify a specific Ruby version. For example, to install Ruby 3.0.2, enter the following command:

```
rvm install 3.0.2
```

<img src="https://customer.acecloudhosting.com/index.php?rp=/images/kb/1560_Image9.png" alt="" height="205" width="800">

**Step 7: Setting the default Ruby version**

You can set the default version of Ruby, if you've installed multiple versions, using the following command:

```
rvm --default use ruby-[3.0.0]
```

<img src="https://customer.acecloudhosting.com/index.php?rp=/images/kb/1561_Image10.png" alt="" height="80" width="800">

In case, you have downloaded the default ruby version, use the following command to set the default:

```
rvm --default use ruby
```

**Step 8: Verifying the installation**

To verify that Ruby is installed and working correctly, enter the following command in your terminal:

```
ruby -–version
```

![](https://customer.acecloudhosting.com/index.php?rp=/images/kb/1562_Image11.png)

**Step 9: Testing the Ruby Environment**

We can start by creating a simple program, which will verify that your environment is properly configured and help you become familiar with creating and executing a Ruby program. Create a new file using your preferred text editor, with the command below:

```
nano program.rb
```

Type the following lines in the recently created file:

```
puts "My First Program"
```

<img src="https://customer.acecloudhosting.com/index.php?rp=/images/kb/1564_Image12.png" alt="" height="104" width="800">

Save and exit by pressing Ctrl + O and then Ctrl + X. Now, let's run the program, using the following command:

```
ruby program.rb
```

<img src="https://customer.acecloudhosting.com/index.php?rp=/images/kb/1563_Image13.png" alt="" height="55" width="800">

### **Conclusion**

You now have Ruby installed on your Ubuntu system using RVM.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.acecloud.ai/knowledge-base/tutorials/how-to-install-ruby-on-ubuntu-20.04-and-setup-programming-environment.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
