In this post, we will show you how to install Ruby on an Ubuntu 18.04 VPS.
Ruby is a dynamic, open-source, object-oriented programming language with a focus on simplicity and productivity. It is best known for its use in the Ruby on Rails framework.
Installing Ruby is an easy task and should not take more than 10 minutes. Let’s begin with the installation.
Method 1: Installing Ruby with RVM
Before starting, you’ll need to log into your server first. You will need to log in as the root account, or as a user with sudo privileges.
NOTE: This method, while not the fastest, will get you the latest version of Ruby (as well as any specific version) installed onto your server. If your application supports a wider range of Ruby versions, then installing using Method 2 (further down in the tutorial) might be the better way, as it is faster.
RVM is a command-line tool that helps you to install, manage and work with multiple Ruby versions.
The following packages are required to install Ruby with RVM and build Ruby gems on your Ubuntu server. Run this command to install them:
sudo apt-get install curl gnupg gnupg2 build-essential libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
Once those packages are installed, install the RVM GPG keys:
sudo gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
The command output will look like this:
gpg: key 105BD0E739499BDB: 5 signatures not checked due to missing keys gpg: key 105BD0E739499BDB: public key "Piotr Kuczynski <email@example.com>" imported gpg: key 3804BB82D39DC0E3: 103 signatures not checked due to missing keys gpg: key 3804BB82D39DC0E3: "Michal Papis (RVM signing) <firstname.lastname@example.org>" not changed gpg: no ultimately trusted keys found gpg: Total number processed: 2 gpg: imported: 1 gpg: unchanged: 1
Install RVM by running the following command:
curl -sSL https://get.rvm.io | sudo bash -s stable
Once RVM is installed you will see the following output:
Downloading https://github.com/rvm/rvm/archive/1.29.7.tar.gz Downloading https://github.com/rvm/rvm/releases/download/1.29.7/1.29.7.tar.gz.asc gpg: Signature made Thu 03 Jan 2019 04:01:48 PM CST gpg: using RSA key 7D2BAF1CF37B13E2069D6956105BD0E739499BDB gpg: Good signature from "Piotr Kuczynski <email@example.com>" [unknown] gpg: WARNING: This key is not certified with a trusted signature! gpg: There is no indication that the signature belongs to the owner. Primary key fingerprint: 7D2B AF1C F37B 13E2 069D 6956 105B D0E7 3949 9BDB GPG verified '/usr/local/rvm/archives/rvm-1.29.7.tgz' Creating group 'rvm' Installing RVM to /usr/local/rvm/ Installation of RVM in /usr/local/rvm/ is almost complete: * First you need to add all users that will be using rvm to 'rvm' group, and logout - login again, anyone using rvm will be operating with `umask u=rwx,g=rwx,o=rx`. * To start using RVM you need to run `source /etc/profile.d/rvm.sh` in all your open shell windows, in rare cases you need to reopen all shell windows. * Please do NOT forget to add your users to the rvm group. The installer no longer auto-adds root or users to the rvm group. Admins must do this. Also, please note that group memberships are ONLY evaluated at login time. This means that users must log out then back in before group membership takes effect!
To start using RVM you need to run:
You can now install the latest version of Ruby with the following command:
rvm install ruby rvm --default use ruby
The command will build Ruby from source and will take some time to complete. The output will look like this:
ruby-2.6.0 - #extracting ruby-2.6.0 to /usr/local/rvm/src/ruby-2.6.0..... ruby-2.6.0 - #configuring...................................................................... ruby-2.6.0 - #post-configuration.. ruby-2.6.0 - #compiling............. ............................................................................ ruby-2.6.0 - #installing............... ruby-2.6.0 - #making binaries executable.. Installed rubygems 3.0.1 is newer than 2.7.8 provided with installed ruby, skipping installation, use --force to force installation. ruby-2.6.0 - #gemset created /usr/local/rvm/gems/ruby-2.6.0@global ruby-2.6.0 - #importing gemset /usr/local/rvm/gemsets/global.gems................................................................ ruby-2.6.0 - #generating global wrappers....... ruby-2.6.0 - #gemset created /usr/local/rvm/gems/ruby-2.6.0 ruby-2.6.0 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem list ruby-2.6.0 - #generating default wrappers....... ruby-2.6.0 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake). Install of ruby-2.6.0 - #complete Ruby was built without documentation, to build it run: rvm docs generate-ri
Verify the ruby version by running the following command:
At the time of writing this article, the latest version of Ruby is 2.6.0.
ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-linux]
You can also install Bundler to be able to manage application gem dependencies:
gem install bundler --no-rdoc --no-ri
If you want to install a specific Ruby version, use this format to define the version you want to install:
rvm install ruby-X.X.X rvm --default use ruby-X.X.X
For example, to install Ruby version 2.5.1 on your Ubuntu server, the command would follow this format:
Now just $43 .99
rvm install ruby-2.5.1 rvm --default use ruby-2.5.1
Method 2: Install Ruby with Apt
The easiest way to install Ruby is from the Ubuntu APT repository.
Update the Ubuntu package lists to get information on the newest versions of packages and their dependencies, and install Ruby using the following commands:
sudo apt-get update sudo apt-get install ruby-full
To check the version of Ruby that was installed, run the following command:
At the time of writing this article, the ruby-full package provides Ruby 2.5.1.
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]
Congratulations, you now have Ruby installed on your Ubuntu 18.04 VPS.
Of course, you don’t have to install Ruby on Ubuntu 18.04 if you use one of our Ruby VPS hosting services, in which case you can simply ask our expert Linux admins to install Ruby on Ubuntu 18.04 for you. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post on how to install Ruby on Ubuntu 18.04, please share it with your friends on the social networks using the share shortcuts below, or simply leave a comment down in the comments section. Thanks.