How to install Ruby 2 on Ubuntu without RVM

Solution 1:

sudo apt-get -y update
sudo apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev
cd /tmp
wget http://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p451.tar.gz
tar -xvzf ruby-2.0.0-p451.tar.gz
cd ruby-2.0.0-p451/
./configure --prefix=/usr/local
make
sudo make install

from here How do I install ruby 2.0.0 correctly on Ubuntu 12.04?

UPDATE

for ruby 2.1.5

sudo apt-get -y update
sudo apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev
cd /tmp
wget http://ftp.ruby-lang.org/pub/ruby/2.1/ruby-2.1.5.tar.gz 
tar -xvzf ruby-2.1.5.tar.gz
cd ruby-2.1.5/
./configure --prefix=/usr/local
make
sudo make install

if you are still seeing an older ruby check your symlink ls -la /usr/bin/ruby from hector

Solution 2:

sudo apt-add-repository ppa:brightbox/ruby-ng-experimental &&
sudo apt-get update &&
sudo apt-get install -y ruby2.0 ruby2.0-dev ruby2.0-doc

Easy to use ^ㅡ^

Solution 3:

# Adds Ruby 2.2 to Ubuntu 14.04
sudo apt-add-repository ppa:brightbox/ruby-ng
# Adds Ruby v1.9/2.0/2.1/2.2 to Ubuntu 14.04/15.04
# sudo add-apt-repository ppa:brightbox/ruby-ng-experimental

sudo apt-get update
sudo apt-get install ruby2.2 ruby2.2-dev

# http://stackoverflow.com/a/1892889/2126990
# priority ruby: https://gist.github.com/brodock/7693207
sudo update-alternatives --remove ruby /usr/bin/ruby2.2
sudo update-alternatives --remove irb /usr/bin/irb2.2
sudo update-alternatives --remove gem /usr/bin/gem2.2

sudo update-alternatives \
    --install /usr/bin/ruby ruby /usr/bin/ruby2.2 50 \
    --slave /usr/bin/irb irb /usr/bin/irb2.2 \
    --slave /usr/bin/rake rake /usr/bin/rake2.2 \
    --slave /usr/bin/gem gem /usr/bin/gem2.2 \
    --slave /usr/bin/rdoc rdoc /usr/bin/rdoc2.2 \
    --slave /usr/bin/testrb testrb /usr/bin/testrb2.2 \
    --slave /usr/bin/erb erb /usr/bin/erb2.2 \
    --slave /usr/bin/ri ri /usr/bin/ri2.2

update-alternatives --config ruby
update-alternatives --display ruby

$ irb
irb(main):001:0> RUBY_VERSION
=> "2.2.0"

$ ruby --version
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux-gnu]

Solution 4:

Since this question was answered I have found a new alternative here:

https://www.brightbox.com/docs/ruby/ubuntu/

In short:

# For ubuntu >= 14.04 install software-properties-common
# instead of python-software-properties
sudo apt-get install python-software-properties
sudo apt-add-repository ppa:brightbox/ruby-ng
sudo apt-get update

sudo apt-get -y install ruby2.2 ruby-switch
sudo ruby-switch --set ruby2.2

I must say that according to my tests this is faster than the alternatives shown here, because the compiling step is skipped.