Ruby is a dynamic, open-source programming language known for its clean, readable syntax. It powers the Ruby on Rails web framework and is widely used for web development, scripting, and DevOps automation with tools like Chef, Puppet, and Vagrant.
This guide covers three methods to install Ruby on Ubuntu 18.04. Use the apt method for servers where a single version is enough. Use Rbenv or RVM when you need to switch Ruby versions across different projects.
<strong>Prerequisite:</strong> You need sudo access.
Installing from the Ubuntu repositories requires no extra tools:
bashsudo apt updatesudo apt install ruby-full
The ruby-full package installs the complete Ruby standard library: the interpreter, the interactive shell (irb), the documentation generator (rdoc), and the rake build tool. Installing just the ruby package without the -full suffix gives only the minimal interpreter without these extras.
Verify the installation:
bashruby --version
Ubuntu 18.04 ships Ruby 2.5.1 in its main repositories. This method works well for single-version server deployments where upgrades follow the Ubuntu LTS release cycle.
Rbenv is a lightweight Ruby version manager that works through shims — small wrapper scripts that redirect Ruby commands to the correct installed version. It does not modify shell built-ins or inject shell functions, which makes it easier to uninstall or disable than RVM.
Install the required build dependencies, then run the rbenv installer:
bashsudo apt updatesudo apt install git curl libssl-dev libreadline-dev zlib1g-dev autoconf bison build-essential libyaml-dev libncurses5-dev libffi-dev libgdbm-devcurl -sL https://github.com/rbenv/rbenv-installer/raw/main/bin/rbenv-installer | bash -
The installer clones both rbenv and ruby-build into ~/.rbenv. The ruby-build plugin is required because rbenv itself does not compile Ruby ruby-build provides the rbenv install command.
Add rbenv to your PATH. For Bash:
bashecho 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrcecho 'eval "$(rbenv init -)"' >> ~/.bashrcsource ~/.bashrc
The eval "$(rbenv init -)" line inserts the shims directory at the front of the PATH and enables shell completion for rbenv commands.
Install Ruby and set it as your global default:
bashrbenv install 2.5.1rbenv global 2.5.1ruby -v
rbenv global sets the default for your entire user account. Use rbenv local 2.5.1 inside a project directory to create a .ruby-version file that pins that project to a different version without changing the global setting. To list all installable versions: rbenv install -l.
RVM (Ruby Version Manager) is a full-featured version manager that adds gemset support — isolated collections of installed gems per project, even within the same Ruby version. This is useful when two projects need conflicting gem versions.
Import the RVM team’s GPG keys and run the installer:
bashgpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDBcurl -sSL https://get.rvm.io | bash -s stablesource ~/.rvm/scripts/rvm
The source command activates RVM in the current session. Add it to ~/.bashrc to load automatically in future shells.
Install Ruby and set it as the default:
bashrvm install 2.5.1rvm use 2.5.1 --defaultruby -v
Which method fits your situation:
All three methods give you a working Ruby installation on Ubuntu 18.04. The right choice depends on how much version flexibility your workflow needs. Leave a comment below if you run into any issues.