How to install Ruby on Ubuntu 20.04 and setup programming environment?
Last updated
Last updated
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:
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
· Red box- input.
· Green box- Output.
Step 1: Enter as Root User
Step 2: Update the system
Begin by updating the system repositories using the following command:
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:
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:
Once you have the dependencies installed, you can install RVM. Enter the following command in your terminal:
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:
This command will load RVM into your shell session.
Note: If you get the following error:
You may try using the following command to load rvm files:
Step 6: Installing Ruby
Now that RVM is installed and loaded, you can install Ruby by entering the following command in your terminal:
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:
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:
In case, you have downloaded the default ruby version, use the following command to set the default:
Step 8: Verifying the installation
To verify that Ruby is installed and working correctly, enter the following command in your terminal:
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:
Type the following lines in the recently created file:
Save and exit by pressing Ctrl + O and then Ctrl + X. Now, let's run the program, using the following command:
You now have Ruby installed on your Ubuntu system using RVM.