Ruby is an object-oriented interpreted programming language that Yukihiro Matsumoto created. This open-source language has a lot of use cases, such as creating web applications and data analytics.
Ruby is loved for its simple syntax, which makes it feel like developers are coding in English.
On the other hand, Ubuntu, a Linux distribution based on Debian, is one of the most famous free and open-source operating systems. The ease of use of Ubuntu has made it popular with developers. If you don’t have Ubuntu installed on your PC, you can get it from the official website.
Installing Ruby on Ubuntu 22.10 is your first step towards creating various solutions using this powerful language.
This article will discuss the 3 different approaches to installing the Ruby development environment in Ubuntu 22.10.
Install Ruby Using Ubuntu 22.10 repository
This approach uses the built-in apt package manager to install Ruby on Ubuntu 22.10. You can achieve this by following these steps;
Step 1: Update packages
The first step is to update the system packages on your Ubuntu operating system. Open your terminal and use the following command;
sudo apt update
Step 2: Upgrade the system
This step upgrades the entire system. Use this command;
sudo apt upgrade
Step 3: Install Ruby
You are now ready to install Ruby. Use this command;
sudo apt install ruby-full
After the installation process is over, you can check the Ruby version installed using this command;
You will get a similar output to this one;
This is the easiest way to install Ruby on Ubuntu 22.10. However, this approach has its downsides.
May not install the latest Ruby version: This approach installs the Ruby version on the Ubuntu package repositories, which may not be the latest Ruby version.
Does not install multiple Ruby versions: Ruby works with various gems (libraries/packages) to provide additional functionality. Some of these gems work with only specific Ruby versions. The next two approaches solve this challenge.
Install Ruby using Ruby Version Manager (RVM)
Ruby Version Manager, or rvm, is a command line tool allowing developers to install, manage and work with multiple Ruby environments. rvm has various solutions for developers in various development stages, such as production, development, testing, and Gem management. Follow these steps to install Ruby using rvm;
Step 1: Update Ubuntu Packages
Get your system ready for installation using this command;
sudo apt update
Step 2: Add Ubuntu dependencies
Ruby requires various dependencies to run properly on Ubuntu. Run this command to install all the dependencies;
Check all the available Ruby versions using this command;
rbenv install -l
Step 9: Install Ruby
For demonstration purposes, we will install Ruby-3.2.1. Use this command;
Rbnev install 3.2.1
Step 10: Set the installed Ruby version as the default
rbenv global 3.2.1
How to update rbnev
We have installed rbnev using Git. Whenever a new version is created, you can install it through these commands;
How to uninstall Ruby using rbnev
As time passes, you may have more Ruby versions than you need in your machine. You can uninstall such ruby versions using this command;
rbenv uninstall (ruby version)
If, for instance, you want to uninstall Ruby 3.2.1, then the command will be;
rbenv uninstall 3.2.1
How to uninstall rbnev
Step 1: Remove rbnev files from bash.
Use this command to open the code editor;
Step 2: Locate these files and delete them, save and exit
eval "$(rbenv init -)"
Step 3: Remove rbnev and associated files
Use this command;
rm -rf `rbenv root`
You can now log out to let the changes apply.
Create a simple Program in Ruby
Since we now have Ruby installed on Ubuntu, we can create a hello world to demonstrate how it works. All Ruby files should have a .rb extension. We can use the inbuilt code editor for demonstration purposes;
Step 1: Create a hello.rb file using nano.
Use this command
Step 2: Add this text to your editor;
puts "hello world"
Step 3: Save and exit the editor
Step 4: Run this command;
The following should be displayed as the output;
Frequently Asked Questions
Is Ubuntu 22.10 paid software?
No. Ubuntu is open-source software that you can download for free. Ubuntu operates under GNU GENERAL PUBLIC LICENSE.
What are the different approaches to installing Ruby on Ubuntu 22.10?
There are three major approaches; the Ubuntu repository, rvm, and rbnev. The last two options are the most advisable.
What is better between rvm and rbnev in installing Ruby on Ubuntu 22.10?
Both rvm and rbnev are designed to achieve the same goal, manage different Ruby versions. The choice between the two will be a matter of preference and taste.
Can you have both rvm and rbnev on your PC?
Yes, but not advisable. The two tools are likely to conflict if they are not configured properly. Using both tools in the same Ruby application is not advisable as it may lead to inconsistencies.
You now have the different approaches you can use to install Ruby on Ubuntu 22.10. The first option is the easiest, but its biggest disadvantage is that you can manage different Ruby options on your local machine.
Both rvm and rbnev are designed to achieve the same goals. Choosing between rvm and rbnev is a matter of preference. You can use either to install libraries and frameworks such as Ruby on Rails and Sinatra, which are packaged as gems.
Python is a very versatile language, and Python developers often have to work with a variety of files and get information stored in them for processing. One popular file format you’re bound to encounter as a Python developer is the Portable Document Format popularly known as PDF