In this blog post, we will be discussing how to install Ruby on an Ubuntu machine. Ruby is an object-oriented, dynamic, and open-source programming language. It is widely used for web development, especially with the Ruby on Rails framework. So, let’s get started with installing Ruby on your Ubuntu system.
Step 1: Update the System
First, it’s always a good idea to update your Ubuntu system to make sure you have the latest packages and security patches. Open a terminal and run the following command:
sudo apt-get update && sudo apt-get upgrade
Step 2: Install Ruby with the package manager
One of the easiest ways to install Ruby on Ubuntu is by using the default package manager apt. Use the following command to install Ruby:
sudo apt-get install ruby-full
This command installs the latest version of Ruby available in the Ubuntu repositories. The ruby-full package includes all the necessary components and dependencies required for running Ruby on your system.
Step 3: Verify the Installation
After the installation is complete, you can check the installed Ruby version by running the following command:
If Ruby is installed successfully, you should see the version number in the output.
Alternative: Install Ruby with rbenv
If you need more control over the Ruby version or want to manage multiple Ruby versions, you can use a tool called rbenv. Follow these steps to install Ruby using rbenv:
Step 1: Install Dependencies
Before installing rbenv, make sure you have the required dependencies installed. Run the following command:
sudo apt-get install git curl libssl-dev libreadline-dev zlib1g-dev autoconf bison build-essential libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev
Step 2: Install rbenv and ruby-build
Clone the rbenv repository from GitHub and set up the environment:
git clone https://github.com/rbenv/rbenv.git ~/.rbenv echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(rbenv init -)"' >> ~/.bashrc source ~/.bashrc
Next, clone the ruby-build repository and install it as an rbenv plugin, which will allow you to install different Ruby versions easily:
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc source ~/.bashrc
Step 3: Install Ruby with rbenv
Now you can install any Ruby version you want. For example, to install Ruby 2.7.2, run the following command:
rbenv install 2.7.2
After the installation is complete, set the installed Ruby version as the default version for your system:
rbenv global 2.7.2
Step 4: Verify the Installation
Check the installed Ruby version with the following command:
If everything is set up correctly, you should see the Ruby version you installed with rbenv.
Now you know how to install Ruby on your Ubuntu system using the default package manager or rbenv. With Ruby installed, you can start developing your next great application. Have fun coding!