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?

Mahmoud Khaled
  • 6,026
  • 6
  • 31
  • 41
  • 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 '13 at 14:31

6 Answers6

101
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

Community
  • 1
  • 1
danmanstx
  • 1,552
  • 1
  • 14
  • 19
  • 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 – lightswitch05 Mar 12 '14 at 01:15
  • My Ruby is now at version 2, but irb is still 1.9.3. How can I fix that? – Daniil Shevelev Jul 16 '14 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? – Randall Flagg Sep 02 '14 at 05: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. – Hector Correa Nov 16 '14 at 16:57
  • @Dash Before installing Ruby 2.x remove old ruby. Check this issue http://stackoverflow.com/questions/3957730/how-can-i-uninstall-ruby-on-ubuntu – TheodorosPloumis Feb 26 '15 at 19:37
  • 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 https://github.com/sstephenson/ruby-build/issues/690 – TheodorosPloumis Feb 26 '15 at 19:46
  • Hello guy's thanks for this nice way. Firstly when i do make check it throw me 22 failures and 6 errors is it ok to use in prod ? If no what should I do to correct it. Secondly, In the long term how can I update ruby or remove it in a clean way? I guess the update need a remove before an update then the same command make the deal. But how remove it? I guess it won't be easy as apt-get purge. – Guillaume Sep 13 '15 at 22:12
  • @Guillaume did you found an easy way to remove it? – dotmindlabs Jun 13 '16 at 08:20
  • Worked like a champ for Ruby 2.3.1 with this wget: `wget https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.1.tar.gz` – Dave Collins Feb 17 '17 at 18:41
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 ^ㅡ^

Dokdo
  • 571
  • 3
  • 2
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]
Denis Denisov
  • 662
  • 8
  • 17
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.

kikito
  • 48,656
  • 29
  • 134
  • 183
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.

DMCoding
  • 881
  • 1
  • 11
  • 26
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
Gautam Gahlawat
  • 154
  • 1
  • 7
  • 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 '18 at 16:30