(January 2019) To install Ruby using the Rbenv script, follow these steps:
1. First, update the packages index and install the packages required for the ruby-build tool to build Ruby from source:
sudo apt-get remove ruby
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
2. Next, run the following curl command to install both rbenv and ruby-build:
curl -sL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer | bash -
3. Add $HOME/.rbenv/bin to the system PATH.
If you are using Bash, run:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc
If you are using Zsh run:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(rbenv init -)"' >> ~/.zshrc
source ~/.zshrc
4. Install the latest stable version of Ruby and set it as a default version with:
rbenv install 2.5.1
rbenv global 2.5.1
To list all available Ruby versions you can use:
rbenv install -l
5. Verify that Ruby was properly installed by printing out the version number:
ruby -v
# Output
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
SOURCE: How To Install Ruby on Ubuntu 18.04
EDIT: Install rubygems:
sudo apt-get install rubygems