• 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 22.04 LTS

Written by Admin, Updated On January 19, 2023
rails, ruby, ubuntu
How to Install Ruby on Ubuntu 22.04

Ruby is popular, dynamic and flexible open source programming language. It has an elegant syntax that is natural to read and easy to write. We’ll show how to install Ruby using the Rbenv and RVM scripts on your Ubuntu 22.04 system. Choose the installation method that is most appropriate for your setup and environment.

How to Install Ruby on Ubuntu 22.04#

There are two ways to install Ruby on Ubuntu 22.04 system:

Install Ruby with Rbenv#

Rbenv is a Ruby version management tool that allows you to switch Ruby versions easily. By default Rbenv doesn’t handle installing Ruby versions so we also need to install ruby-build that will help you to install specific version of Ruby.

Follow the below instruction as root or sudo user to install Ruby with Rbenv:

Step 1 – Update Package Index#

Update the package index list by typing:

sudo apt update

Step 2 – Install Dependencies#

Now, 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, simply clone rbenv GitHub repository into the ~/.rbenv folder:

git clone https://github.com/rbenv/rbenv.git ~/.rbenv

Step 3 – Setup Rbenv#

Next, run the following commands to set up rbenv:

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

Step 4 – Download Ruby-Build Plugin#

Now download the ruby-build plugin into the plugins folder of rbenv as follows:

git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL

The ruby-build plugin adds the install command to rbenv.

To get a list of all Ruby versions that can be installed with rbenv enter:

rbenv install -l

Step 5 – Install Ruby#

To install Ruby version 3.2.0and set it as default version, type:

rbenv install 3.2.0
rbenv global 3.2.0

Step 6 – Verify Installation#

Verify installation by issuing below command:

ruby -v

Install Ruby using RVM#

RVM is a command-line tool which allows you to easily install, manage, and work with multiple ruby environments from interpreters to sets of gems.

Perform the following steps:

Step 1 – Install Dependencies#

Install the dependencies required to build Ruby from source:

sudo apt update
sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev

Step 2 – Add GPG Key#

Run the following commands to add the GPG key and install RVM:

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
curl -sSL https://get.rvm.io | bash -s stable

To start using RVM, type:

source ~/.rvm/scripts/rvm

Step 3 – Install Ruby#

Install the latest stable version 3.2.0 of Ruby with RVM and set it as the default version:

rvm install 3.2.0
rvm use 3.2.0 --default

Step 4 – Verify Installation#

Verify that Ruby installed properly by checking it’s version:

ruby -v

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:

Ruby Simple Demo

Conclusion#

We shown you two methods to install Ruby on Ubuntu 22.04 system. The method depends on your requirements and preferences, while most people prefer using rbenv these days.

If you have any problem or suggestion please leave a comment below.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 PHP 8.2 on Debian 11 Linux
Next Article   How to Set Up Apache Virtual Hosts on Ubuntu 22.04

Related Posts

  • How to Install Apache, MySQL, PHP (LAMP) on Ubuntu 22.04

    How to Install LAMP on Ubuntu 22.04

    March 20, 2023
  • How to Install LEMP Stack on Ubuntu 22.04

    How to Install LEMP Stack on Ubuntu 22.04

    March 18, 2023
  • How to Install Memcached on Ubuntu 22.04

    How to Install Memcached on Ubuntu 22.04

    March 16, 2023

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install Microsoft Edge Browser on Ubuntu 22.04
    How to Install Microsoft Edge Browser on Ubuntu 22.04 March 14, 2023
  • How to Install Ruby on Ubuntu 22.04 LTS
    How to Install Ruby on Ubuntu 22.04 LTS February 27, 2023
  • How to Install LEMP Stack on Ubuntu 22.04
    How to Install LEMP Stack on Ubuntu 22.04 March 18, 2023
  • How to Install Set Up Apache Virtual Hosts on Ubuntu 22.04
    How to Set Up Apache Virtual Hosts on Ubuntu 22.04 March 2, 2023
  • How to Install MariaDB on Debian 11 Bullseye
    How to Install MariaDB on Debian 11 Bullseye March 8, 2023
© 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