Ruby is one of the most popular languages today. It has an elegant syntax and it is the language behind the powerful Ruby on Rails framework.
In this tutorial, we will show you three different ways to install Ruby on Ubuntu 20.04 system.
Before starting with the tutorial, make sure you are logged in as a user with Sudo privileges.
Installing Ruby from Ubuntu Repositories
The easiest way to install Ruby on your Ubuntu system is through the
apt package manager. At the time of writing, the version in the Ubuntu repositories is 2.6.5 which is the latest stable version of Ruby.
To install Ruby from the default Ubuntu repositories, follow these steps:
First, update the packages index:
sudo apt install curl
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash –
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add –
echo “deb https://dl.yarnpkg.com/debian/ stable main” | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update
sudo apt-get install git-core zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev nodejs yarn
Next, we’re going to be installing Ruby using one of three methods. Each have their own benefits, most people prefer using rbenv these days, but if you’re familiar with rvm you can follow those steps as well. I’ve included instructions for installing from source as well, but in general, you’ll want to choose either rbenv or rvm.
Choose one method. Some of these conflict with each other, so choose the one that sounds the most interesting to you or go with my suggestion, rbenv.
Using rbenv (Recommended)
Installing with rbenv is a simple two-step process. First, you install rbenv, and then ruby-build:
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo ‘export PATH=”$HOME/.rbenv/bin:$PATH”‘ >> ~/.bashrc
echo ‘eval “$(rbenv init -)”‘ >> ~/.bashrc
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo ‘export PATH=”$HOME/.rbenv/plugins/ruby-build/bin:$PATH”‘ >> ~/.bashrc
rbenv install 2.6.5
rbenv global 2.6.5
The last step is to install Bundler:
gem install bundler
rbenv users need to run rbenv rehash after installing bundler.
We’ll be using Git for our version control system so we’re going to set it up to match our Github account. If you don’t already have a Github account, make sure to register. It will come in handy for the future.
Replace my name and email address in the following steps with the ones you used for your Github account.
git config –global color.ui true
git config –global user.name “YOUR NAME”
git config –global user.email “YOUR@EMAIL.com”
The next step is to take the newly generated SSH key and add it to your Github account. You want to copy and paste the output of the following command and paste it here.
ssh-keygen -t rsa -b 4096 -C “email@example.com” [This will display keys in terminal]
Add that key to Github or bitbucket
Hi, excited! You’ve successfully authenticated, but GitHub does not provide shell access.
Choose the version of Rails you want to install:
gem install rails -v 126.96.36.199
If you’re using rbenv, you’ll need to run the following command to make the rails executable available:
Now that you’ve installed Rails, you can run the rails -v command to make sure you have everything installed correctly:
# Rails 188.8.131.52