How to Install Ruby on Ubuntu Linux
Installing Ruby on Ubuntu Linux lets you build apps and run Ruby code.
Ruby is a widely-used, free programming language famous for its clean writing style and how quickly you can create things with it. It’s often paired with web tools like Ruby on Rails.
On Ubuntu, the easiest way to get Ruby is using the `apt` tool. This usually installs Ruby 3.0 or a more recent version on current Ubuntu setups. If you need to switch between different Ruby versions for various projects, tools called Rbenv or RVM give you that flexibility.
Install Ruby on Ubuntu Linux by first updating your package list with `sudo apt update`. Then, install the `ruby-full` package using `sudo apt install ruby-full`. Verify the installation by running `ruby –version`.
How to install Ruby on Ubuntu Linux
As described above, Ruby is a popular, high-level programming language focused on simplicity. It has an elegant syntax that is easy to read and write and is behind the powerful Ruby on Rails Framework.
Install Ruby via Apt
You can install Ruby on Ubuntu using the apt package manager by running two simple commands in your terminal. First, update your software list with `sudo apt update`, then install the `ruby-full` package with `sudo apt install ruby-full`. This is the quickest way to install Ruby on Ubuntu for most users.
sudo apt update sudo apt install ruby-full
To verify if Ruby is installed, run the commands below:
ruby --version
It should output a similar line as below:
Ouput:
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]Install Ruby via Rbenv
Rbenv lets you manage multiple Ruby versions on your Ubuntu system, and you’ll need the ruby-build tool to install Ruby with it. Before installing Ruby using Rbenv, you must first install some required software packages that ruby-build needs. We’ll use ruby-build to get Ruby on your Ubuntu machine.
To get Ruby, we’ll need to use ruby-build. To install Ruby-build, run the commands below to install dependencies.
sudo apt update 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 commands below to clone both Rbenv and Ruby-build repositories at Github.
curl -sL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer | bash -
Next, run the commands below if you’re running Bash Shell in Ubuntu.
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(rbenv init -)"' >> ~/.bashrc exec $SHELL
If you’re running Z Shell, run the lines below:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc echo 'eval "$(rbenv init -)"' >> ~/.zshrc source ~/.zshrc
After the steps above, you can install any available version of Ruby. To list the available versions, run the commands below:
rbenv install -l
Then, install the version you want by using the commands below. For this post, we’re installing Ruby 2.5.1.
rbenv install 2.5.1 rbenv global 2.5.1
Replace the version number with the correct one that suits your environment.
To verify the Ruby version, run the commands below:
ruby -v
It should output a similar line as below:
Output:
ruby 2.5.1p206 (2019-10-01 revision 67816) [x86_64-linux]Install Ruby via RVM
RVM is a popular tool for installing and managing different Ruby versions on Ubuntu. To get Ruby using RVM, you first need to install some essential software. Open your terminal, run the update command, and then install the packages RVM needs to manage Ruby on your system.
First, install dependencies by running the commands below:
sudo apt update 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
Then, run the commands below to install RVM.
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB curl -sSL https://get.rvm.io | bash -s stable
After that, run the command below to activate RVM
source ~/.rvm/scripts/rvm
To install Ruby, run the commands below:
rvm install 2.5.1 rvm use 2.5.1 --default
To verify if Ruby is installed, run the commands below:
ruby -v
It should output a similar line as below:
Output:
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]Conclusion:
- Ruby is a versatile and high-level programming language ideal for web development.
- Multiple methods are available for installing Ruby on Ubuntu Linux, including using the apt package manager, Rbenv, and RVM.
- Each installation method has its advantages, such as simplicity with apt and version management with Rbenv and RVM.
- Verifying the installation is straightforward by checking the Ruby version through the command line.
- With Ruby installed, you can begin developing robust applications, leveraging the powerful Ruby on Rails framework and a vast array of libraries.
Was this guide helpful?
About the Author
Richard
Tech Writer, IT Professional
Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.
No comments yet — be the first to share your thoughts!