# 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
```

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

**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
```

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

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
```

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

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
```

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

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
```

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

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
```

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

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

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

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

**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
```

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

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
```

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

**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]
```

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

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"
```

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

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

```
ruby program.rb
```

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

### **Conclusion**

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