• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Install Ruby on Ubuntu 18.04

Written by Admin, Updated On July 18, 2019
ruby, ubuntu
How To Install Ruby on Ubuntu 18.04

Ruby is one of the most popular language nowadays. Ruby is used for web applications and also for games etc. In this tutorial we will show you steps to install Ruby on Ubuntu 18.04. It’s used with Ruby on Rails framework.

Prerequisites#

Before you start installation, ensure that you are logged in with non-root user account with sudo privileges.

Installing Ruby from Ubuntu Repositories#

Ruby package is available in the default Ubuntu repositories. So you can install it using apt package manager. To install Ruby from the default Ubuntu repositories, follow these steps:

At first, update the packages index list:

sudo apt update

Next install Ruby using below command:

sudo apt install ruby-full

You can verify the installation by issuing the below command and it will print the version of installed Ruby.

ruby --version

It should look like as below:

Output
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]

Install Ruby using Rbenv#

Rbenv is a Ruby version management tool. Using this tool you can easily switch the version of Ruby on same system if installed multiple versions. By default Rbenv doesn’t handle installing Ruby versions so we also need to install ruby-build which is a tool that will help you to install specific version of Ruby which you need. Follow the instruction below to install Ruby using Rbenv:

First of all, update the package index list by typing:

sudo apt update

Next we will install dependencies for installation of rbenv and ruby-build:

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

After that run the following curl command to install rbenv and ruby-build:

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

Above command will clone both rbenv and ruby-build repositories from GitHub to ~/.rbenv directory.

Add $HOME/.rbenv/bin to the system PATH.

If you are using Bash, run:

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

If you are using Zsh run:

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

Select the latest and stable version of Ruby and you can set default version as per your need.

rbenv install 2.6.3
rbenv global 2.6.3

You can confirm installation by issuing below command:

ruby -v

It should show output as below:

Output
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]

Ruby Program Example#

We are going to create a simple ruby program. So create a demo.rb file using your favorite editor:

sudo nano demo.rb

Paste below lines in to that file:

puts "Ruby Simple Demo"

Save file and exit from editor using Ctrl+x.

To run demo.rb file issue below command:

ruby demo.rb

It will print simple output as below:

Output
Ruby Simple Demo

Conclusion#

You have successfully learned multiple ways to install Ruby on Ubuntu 18.04 machine. If you have any problem or suggestion please leave a comment below.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Install and Use Docker on CentOS 7
Next Article   How to Install Google Chrome on CentOS 7

Related Posts

  • How to Install Php 8 on Ubuntu 20.04

    How to Install PHP 8 on Ubuntu 20.04

    December 28, 2020
  • How to Install GIMP on Ubuntu 20.04

    How to Install GIMP 2.10 on Ubuntu 20.04

    December 22, 2020
  • How to Install Python 3.9 on Ubuntu 20.04

    How to Install Python 3.9 on Ubuntu 20.04

    December 21, 2020

Leave a Reply Cancel reply

Popular Posts

  • How to Install Python 3.9 on CentOS 8
    How to Install Python 3.9 on CentOS 8 December 31, 2020
  • How to Install Php 8 on Debian 10
    How to Install PHP 8 on Debian 10 January 2, 2021
  • How to Install Php 8 on Ubuntu 20.04
    How to Install PHP 8 on Ubuntu 20.04 December 28, 2020
  • How to Install GIMP 2.10 on CentOS 8
    How to Install GIMP 2.10 on CentOS 8 December 30, 2020
  • How to Install AnyDesk on Debian 10
    How to Install AnyDesk on Debian 10 Buster January 23, 2021
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook