67

I want to install ruby 2.0 using

sudo apt-get install ruby2.0

But there isn't available package for ruby2.0

I want to install it using apt-get install the same like ruby 1.9.1

Any suggestions?

1
  • 3
    There is no Ruby 2 package for Ubuntu 12.04 AFAIK. You have to build it by yourself and then install it using checkinstall.
    – toro2k
    Aug 28, 2013 at 14:31

6 Answers 6

102
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

9
  • 1
    Optionally, run make check to check whether the compiled Ruby interpreter works well. If you see the message "check succeeded", your ruby works as it should Mar 12, 2014 at 1:15
  • My Ruby is now at version 2, but irb is still 1.9.3. How can I fix that? Jul 16, 2014 at 19:39
  • 1
    The install process worked great except for the last command which I had to run as sudo. Also I am still seeing ruby as v 1.9.3. How can I switch to ruby 2? Sep 2, 2014 at 5:27
  • 3
    @RandallFlagg type which ruby and you'll get a path to some location (e.g. /usr/bin/ruby) This path is typically a symlink to the actual Ruby executable. Type ls -la /usr/bin/ruby and you'll probably see it being symlinked to ruby1.9.x. If that's the case, update the symlink to point to the new location. Nov 16, 2014 at 16:57
  • 1
    IMPORTANT for Ruby 2.2.x on Ubuntu 14.04.1 (x86_64). You must also install libffi-dev before compilling. Check this out github.com/sstephenson/ruby-build/issues/690 Feb 26, 2015 at 19:46
57
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 ^ㅡ^

4
  • 2
    what output when you type on terminal which ruby ? Feb 4, 2014 at 14:31
  • 3
    This seams to install Ruby 1.9 and Ruby 2, with 1.9 as the default. How do I make Ruby 2.0 the default? Mar 3, 2014 at 9:59
  • You have a mistake, it "apt-add-repository" no add-apt
    – Ba7a7chy
    Mar 5, 2014 at 12:37
  • 3
    @Ba7a7chy Not really. apt-add-repository is a symlink for add-apt-repository introduced in Ubuntu 11.04.
    – SáT
    Mar 25, 2014 at 21:07
42
# 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]
2
  • 1
    My Ruby is now at version 2, but irb is still 1.9.3. How can I fix that? Jul 16, 2014 at 19:43
  • Appears that update-alternatives part could be skipped. I am getting irb(main):001:0> RUBY_VERSION => "2.1.2" right after apt-get install. Aug 3, 2014 at 13:44
21

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.

6
  • 3
    I can confirm this is both faster, less complicated, and less prone to errors. Sep 14, 2015 at 0:59
  • No Wily Werewolf version is available yet :(
    – Yvo
    Dec 4, 2015 at 18:12
  • You may need apt-get update && apt-get install software-properties-common in order to use apt-add-repository
    – nelsonenzo
    Jan 15, 2016 at 19:21
  • 3
    Works great, this answer deserves to go at the top! Jan 26, 2016 at 13:55
  • I get "Invalid interpreter: ruby2.2", and a listing only shows ruby1.9.1 as an option.
    – RCross
    Jun 22, 2017 at 22:28
0

I particularly like ruby-install, available here: https://github.com/postmodern/ruby-install

It will install ruby (any version), JRuby, etc., and has many other features besides.

0

The better way to install ruby on ubuntu without RVM is to install it with rbenv in terminal as follows:

$ sudo apt-get update

Install the rbenv and Ruby dependencies with apt-get:

$ 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

Now run these commands as follows:

$ 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

Time to install ruby:

$ rbenv install 2.3.3

which ever is the latest and stable version

$ rbenv global 2.3.3

To check the version

$ ruby -v

To disable the local documentation, as this process can be lengthy:

$ echo "gem: --no-document" > ~/.gemrc

Install the bundler gem, to manage your application dependencies:

$ gem install bundler
1
  • The title of this post is "How to install Ruby 2 on Ubuntu without RVM". Note the "WITHOUT RVM" in the title.
    – ChaosFreak
    Jun 16, 2018 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.