Installing Ruby 2.3.1 on Ubuntu

We will be setting up a Ruby environment on Ubuntu.

Installing Ruby 2.3.1 (or earlier).

The first step is to install some dependencies for Ruby.

sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev

Next we're going to be installing Ruby using one of three methods. Each have their own benefits, most people prefer using rbenv these days, but if you're familiar with rvm you can follow those steps as well. I've included instructions for installing from source as well, but in general, you'll want to choose either rbenv or rvm.

  • Using rbenv

Installing with rbenv is a simple two step process. First you install rbenv, and then ruby-build:

cd
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL

git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL

git clone https://github.com/rbenv/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash

rbenv install 2.3.1
rbenv global 2.3.1
ruby -v

OUTPUT:

root@ip-172-31-42-19:~# git clone https://github.com/rbenv/rbenv.git ~/.rbenv
Cloning into '/root/.rbenv'…e
cho 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELLremote: Counting objects: 2500, done.
remote: Total 2500 (delta 0), reused 0 (delta 0), pack-reused 2500
Receiving objects: 100% (2500/2500), 456.36 KiB | 365.00 KiB/s, done.
Resolving deltas: 100% (1546/1546), done.
Checking connectivity… done.
root@ip-172-31-42-19:~# echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
root@ip-172-31-42-19:~# echo 'eval "$(rbenv init -)"' >> ~/.bashrc
root@ip-172-31-42-19:~# exec $SHELL
root@ip-172-31-42-19:~# git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
eCloning into '/root/.rbenv/plugins/ruby-build'…
cho 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL
remote: Counting objects: 6454, done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 6454 (delta 2), reused 0 (delta 0), pack-reused 6446
Receiving objects: 100% (6454/6454), 1.25 MiB | 560.00 KiB/s, done.
Resolving deltas: 100% (3720/3720), done.
Checking connectivity… done.
root@ip-172-31-42-19:~# echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
root@ip-172-31-42-19:~# exec $SHELL
root@ip-172-31-42-19:~# git clone https://github.com/rbenv/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash
Cloning into '/root/.rbenv/plugins/rbenv-gem-rehash'…
remote: Counting objects: 97, done.
remote: Total 97 (delta 0), reused 0 (delta 0), pack-reused 97
Unpacking objects: 100% (97/97), done.
Checking connectivity… done.
root@ip-172-31-42-19:~# rbenv install 2.3.1
rbenv global 2.3.1
ruby -vDownloading ruby-2.3.1.tar.bz2…
-> https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.1.tar.bz2

Installing ruby-2.3.1…


Installed ruby-2.3.1 to /root/.rbenv/versions/2.3.1

root@ip-172-31-42-19:~# rbenv global 2.3.1
root@ip-172-31-42-19:~# ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
root@ip-172-31-42-19:~#

Also you can use rvm and sorce code.

  • Using rvm

The installation for rvm is pretty simple:

sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
curl -sSL https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm install 2.3.1
rvm use 2.3.1 --default
ruby -v
  • From source

Arguably the least useful Ruby setup for development is installing from source, but I thought I'd give you the steps anyways:

cd
wget http://ftp.ruby-lang.org/pub/ruby/2.3/ruby-2.3.1.tar.gz
tar -xzvf ruby-2.3.1.tar.gz
cd ruby-2.3.1/
./configure
make
sudo make install
ruby -v

The last step is to install Bundler

gem install bundler

rbenv users need to run rbenv rehash after installing bundler.

vovando Avatar

Leave a Reply

Your email address will not be published. Required fields are marked *