3 Ways to Install Ruby on Ubuntu 22.04 LTS Jammy
Learn the different commands and steps to install Ruby on Ubuntu 22.04 LTS Jammy JellyFish using the command terminal.
Ruby is an object-oriented, high-level interpreted programming language that is easy to use and productive to use. Inventor Yukihiro Matsumoto wanted to develop a language in which functional and imperative programming are balanced, therefore, this dynamic, free and object-oriented Ruby programming language enjoys great popularity among programmers.
Everything in Ruby is an object that allows any programmer to customize the language to their preferences. Unlike others, the syntax is easier to read and write. It is similar to C and Java, so both Java and C programmers can easily learn Ruby.
Extensive Documents online introduces newcomers to ruby syntax. Many Ruby projects can be found in RubyForge, where you can also find new libraries.
It offers a powerful package manager to distribute Ruby programs and libraries, in a self-contained format called “gem”, as well as tools to easily manage the installation of gems on a server. Ruby programmers also have access to the powerful features of RubyGems.
Ruby supports all major platforms such as Windows, Mac, and Linux.
Steps to Install Ruby on Ubuntu 22.04 LTS
There are three easy ways to install Ruby on Ubuntu Linux here we show them all. Also, the steps given here can be used for other Ubuntu versions such as 20.04/18.04, including other Linuxes – Mint, Debian, Elementary OS, MX Linux, POP_OS, etc.
#1st method using standard Ubuntu repository
1. Run System Update
Let’s first run the system update command which will notify our system’s package manager of the latest packages available through the system repositories.
sudo apt update
2. Install Ruby on Ubuntu 22.04
Yes, we can install Ruby programming language using Ubuntu default repository, however, the version of it will not be the latest one instead of well stable and tested as Ubuntu 22.04 is a taken release long-term support. Therefore, if you want to get the Ruby without adding any additional repository, use the given command:
sudo apt install ruby-full
Once the installation is complete, we can check the version using:
#2nd method using Rbenv
3. Install Rbenv
Rbenv is a command-line tool that allows us to manage multiple versions of Ruby and switch between them. We can also use it to install the latest versions of Ruby using the ruby-build plugin.
Install the required dependencies:
sudo apt install git curl autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev libdb-dev
Obtain the Rbenv installation script:
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash
Add a directory path containing the Rbenv files to your system path to use its command line tool:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
To check the installed version:
4. Install Ruby using Rbenv
Now Rbenv is ready to use on your Ubuntu 22.04 system, we can use it to list and install any latest version of Ruby on our system.
For listing available versions to install we can use:
rbenv install -l
To install any of the listed versions, we can use the syntax shown:
rbenv install version
Replace the “version” in the syntax above with the one you want to install. For example, if you want to install 3.1.2 then the command will be:
rbenv install 3.1.2
How to set the default system-wide version of Ruby:
As we know, we can use rbenv to install and manage multiple versions of Ruby. Therefore, if you have more than two versions on your system and you want to set one of them as your system’s default version, the syntax is:
rbenv global version
Replace the “version” with whatever you want to set as the system-wide default.
rbenv global 3.1.2
To remove any version of ruby:
rbenv uninstall version
#3rd method using Install Ruby using RVM- Ruby Version Manager
5. Install RVM – Ruby Version Manager
Another way to install Ruby on our Ubuntu 22.04 is to use another command line tool called RVM– Ruby version manager.
Ruby Version Manager abbreviated as RVM, is a software platform developed to manage multiple installations of Ruby on the same device which includes the entire ruby environment including the Ruby interpreter and installed RubyGems. This helps developers easily switch between different versions of Ruby according to the requirements of different projects.
sudo apt install curl g++ gcc autoconf automake bison libc6-dev libffi-dev libgdbm-dev libncurses5-dev libsqlite3-dev libtool libyaml-dev make pkg-config sqlite3 zlib1g-dev libgmp-dev libreadline-dev libssl-dev
Install the GPG key
gpg --keyserver hkp://pgp.mit.edu --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
curl -sSL https://get.rvm.io | bash -s stable
After this source, the variables:
6. Get Ruby language on Ubuntu 22.04
Finally, we can use RVM to install the available Ruby versions, to list them we can use the given command:
rvm list known
To install a specific version listed after running the previous command, you can use:
rvm install ruby-version
Replace “version” in the command above with the one you want to install, for example, say you want to have 3.1.2
rvm install ruby-3.1.2
While to simply install the latest version available, use:
rvm install ruby
How to use RVM to set a specific version of Ruby as the system default;
rvm --default use ruby-version
Replace “version” in the command above with the one you want to install
To remove any version of ruby:
rvm remove ruby-version
7. Uninstall or remove
Depending on the method you used to install Ruby, you can remove the same using the given commands:
To remove APT installed Ruby
sudo apt remove ruby-full
To remove Rbenv
rm -rf ~/.rbenv
To remove RVM
rvm implode rm -rf ~/.rvm rm -rf /etc/rvmrc rm -rf ~/.rvmrc
• How to Install Maven on Ubuntu 22.04 LTS Jammy
• How to install CUDA on Ubuntu 20.04 LTS…
• Accessing Ubuntu 22.04 Remote Desktop from Windows…
• 4 Ways to Install Firefox Browser on Ubuntu 22.04…