Thursday, March 28, 2024
HomeTutorialsHow to Install and Use Ruby on Linux Distributions

How to Install and Use Ruby on Linux Distributions

Ruby is one of the most used and easy to use programming languages. Ruby is an open-source, object-oriented interpreter that can be installed on a Linux system. Many programmers prefer Python over Ruby to start learning basic programming, but Ruby can handle large web-frameworks and web applications. Once you start learning Ruby, you would find it less machine-like and not repetitive. If you’re confused between Ruby and Ruby on Rails, I must mention that they are not the same; Ruby is a programming language; on the other hand, Ruby on Rails is a web framework.

Install Ruby On Linux


Ruby is written in the C programming language, and the syntaxes are similar to Perl and Python. Installing Ruby on a Linux system doesn’t require a lot of computing skills. It requires an active internet connection and root privilege to install the Ruby language on any system. If you’re a newbie on Ruby, this post would be helpful for you. Here, I’ll guide you on installing and getting started with Ruby on the Debian, Red Hat, and Arch-based Linux systems.

1. Install Ruby on Debian/Ubuntu Linux


Installing Ruby on a Debian or Ubuntu system is straightforward. There is more than one method that you can use to install it on your machine. Here, we’ll see how you can use the aptitude command and Ruby environment to install Ruby on your Debian-based system.

Method 1: Install Ruby Through Linux Repository


You can run the following command on your terminal shell with root privilege to install Ruby through the aptitude package command on Ubuntu and other Debian-based distributions; the following single command will install Ruby language and the dependency files of Ruby on your Linux system. Don’t forget to update your system repository before installing any packages.

sudo apt update
sudo apt install ruby-full

Ruby Full on Debian

Method 2: Install Ruby Via Ruby Environment


In this method, we’ll see how to create an environment for Ruby and install Ruby through the Ruby environment (Rb Env). First, run the following command on your terminal shell to get the Ruby environment and dependency packages on your system.

sudo apt update
sudo apt install git curl libssl-dev libreadline-dev zlib1g-dev autoconf bison build-essential libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev

curl install ruby env

Now, run the cURL command given below to get the Ruby on your system. The command will pull the installer file from Github.

- -
curl -sL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer | bash -

After setting up the environment and downloading Ruby, you can now run the following bashrc and echo commands on your terminal shell to configure the system.

echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc

Finally, run the following command on your system terminal to install Ruby through the Ruby environment. You can choose between the global and constant versions and select any following commands on your shell.

rbenv install 2.5.1
rbenv global 2.5.1

rbenv env install

When the installation finishes, check the Ruby version to know if It’s installed correctly inside your Linux system or not.

ruby --version

2. Install Ruby on Fedora and Red Hat Linux


If you’re using a Red Hat Linux or a Fedora workstation, It’s now quicker for you to install Ruby on your system. As the newer version of Fedora supports both DNF and YUM, installing packages on Fedora through the YUM command would not be an issue.

You just need to run the following Yum command on the terminal shell to install Ruby’s full package on your Red Hat-based Linux system.

$ sudo yum install ruby

install Ruby on Fedora Linux

3. Install Ruby on Arch Linux


Installing the Ruby language on an Arch-based Linux system is not much different from installing it on other distributions. You can run the following Pacman command on your console with root privileges to install Ruby on your machine.

sudo pacman -S ruby

I’ve used a Manjaro KDE Linux to illustrate the method of Ruby on Arch Linux. You can also execute the above Pacman command on other Arch-based systems.

install Ruby on Arch Linux

If you find any issues installing the package on your Arch and Arch-based system, you can click on this link to download the compiled ZST package of Ruby for your system. After downloading the package, you can install it through the default package installer on your Arch Linux.

ruby zst package for arch

Run Your First Ruby Code


Till now, we’ve seen the methods of installing Ruby on different Linux systems. It’s now time to test the traditional ‘Hello World’ through Ruby on our Linux machine. You can copy the following ‘Hello World ‘ Ruby code to test it on your device.

puts "Hello, World!"

First, open your notepad and write your Ruby code. Then save it with a .rb file extension. Now, run the following cd and ls commands to find the file on your filesystem.

Now type the syntax Ruby then type your file name with the file extension, and hit the Enter button to run the code on your Linux terminal shell. In the output, you would see your first ‘Hello Word’ through Ruby.

ruby hello.rb

hello world

Final Words


Installing Ruby on a Linux system is effortless and trouble-free. In the entire post, I’ve described the methods of installing Ruby on the major Linux distributions. I’ve also demonstrated the method of how to run a simple Ruby code through the terminal shell.

Please share it with your friends and the Linux community if you find this post useful and informative. You can also write down your opinions regarding this post in the comment section.

Mehedi Hasan
Mehedi Hasan
Mehedi Hasan is a passionate enthusiast for technology. He admires all things tech and loves to help others understand the fundamentals of Linux, servers, networking, and computer security in an understandable way without overwhelming beginners. His articles are carefully crafted with this goal in mind - making complex topics more accessible.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

You May Like It!

Trending Now