23

I'm finding the task of installing ruby 2.0 on the latest Ubuntu 14.04 rather frustrating. I'm aware that I could forgo the packages and install from source - but I'd far rather install a package - if that is possible.

I found this question/answer about ruby on 13.10 - which looked like what I wanted.

How to install ruby?

Unfortunately, the strategy doesn't seem viable - the ruby-switch package has been deleted in 14.04.

http://www.ubuntuupdates.org/package/core/trusty/universe/base/ruby-switch

The deletion of the package references a bug which, to me, looks entirely unrelated.

I'm bemused about why installing ruby2.0 using apt-get installs ruby1.9 and makes it the default ruby interpreter. I do get a ruby2.0 binary - but scripts (which depend upon a 2.0 interpreter when executing ruby) don't pick it up. Furthermore, when I use gem et. al. to install ruby packages - these seem to be installed for ruby1.9 rather than 2.0. Very unsatisfactory.

Can anyone offer a hint as to the most straightforward way to install ruby 2.0 as the standard ruby interpreter? How am I expected to switch from ruby 1.9 to 2.0 without ruby-switch?

aSteve
  • 459

5 Answers5

29

For 14.04 I found the following PPAs that come with Ruby 2.x

  • Adds Ruby 2.1 to Ubuntu 14.04

    sudo add-apt-repository ppa:brightbox/ruby-ng
    

I also found in GoRails a set of instructions to install Ruby on 14.04 but I am guessing since they are long you would want a PPA instead.

  • Adds Ruby 1.9, 2.0 or 2.1 to Ubuntu 14.04

    sudo add-apt-repository ppa:brightbox/ruby-ng-experimental
    

After you add one of them simply:

sudo apt-get update
sudo apt-get install ruby2.1 # In the case you want 2.1
muru
  • 207,228
Luis Alvarado
  • 216,643
8

Debian version of Ruby does not support several ruby installations on the same system. Debian obsoleted the package and Ubuntu just removed it from the repositories. You should use rbenv to switch between different ruby versions. This is the recommended way by ruby-switch package description and was the method that has been discussed in bug 737782 as preferred, through it's said that there shouldn't be more than only one version of ruby in the repositories.

Ruby 2.0 is installed by default when installing the ruby2.0 package and no other action is needed. If the package ruby was installed is recommended to remove it. You should have the binary /usr/bin/ruby2.0 available on your system.

Braiam
  • 69,112
8
sudo apt-get install ruby2.0
sudo rm /usr/bin/ruby && sudo ln -s /usr/bin/ruby2.0 /usr/bin/ruby
sudo rm -fr /usr/bin/gem && sudo ln -s /usr/bin/gem2.0 /usr/bin/gem
Eric Carvalho
  • 55,453
5

If you want to switch between rubies, I recommend using rvm (https://rvm.io). It's a package manager and it allows you to install many different rubies (not just Matz's) on one machine, either local to the user or globally for all users.

I know you asked for a "package," so perhaps this isn't going to work for you. But I figured it might help if this is your development machine.

The benefit of doing it this way is that you can install one gemset for 2.1.1 and others for 2.0 or 1.9.3, etc. It also allows you to test jruby, rubinius, etc. without committing your system to one.

I'm not using it on production, but apparently it's suitable for that as well as development.

Here's the quickstart: https://rvm.io/rvm/install

Louis
  • 51
  • 2
1

Late in the game but I think a perhaps more-complete solution than hard-coding symlinks is this use of update-alternatives, posted here verbosely in case others are bitten by the same frustration and would like a more native solution. This handles all binaries and man pages, preemptively removing the references first to avoid conflicts.

Caveats:

  • I think this will need to be rerun if/when one of the ruby versions is updated.
  • I'm not a guru with update-alternatives so it's possible this is overkill and/or done kludgingly.

Script (I named fix-ruby-alternatives.sh):

#!/bin/bash

# Script to insert all potentially alternative-able files within ruby versioned packages
# Bill Evans ("r2evans")
# April 19, 2015

BIN=/usr/bin
MAN=/usr/share/man/man1
MASTER="ruby"
SLAVES=( gem irb rdoc testrb rake erb ri )
VERSIONS=( 1.9.1 2.0 )

DRYRUN="yes"
[[ "$1" = "-y" ]] && unset DRYRUN

PRI=0
for ver in ${VERSIONS[@]} ; do
    PRI=$(( ${PRI} + 1 ))
    REMCMD="update-alternatives --remove ${MASTER} ${BIN}/${MASTER}${ver}"
    CMD="update-alternatives --install ${BIN}/${MASTER} ${MASTER} ${BIN}/${MASTER}${ver} ${PRI}"
    if test -f "${MAN}/${MASTER}${ver}.1.gz" ; then
        CMD="${CMD}    --slave ${MAN}/${MASTER}.1.gz ${MASTER}.1.gz ${MAN}/${MASTER}${ver}.1.gz"
    else
        echo "#  no ${MAN}/${MASTER}${ver}.1.gz" > /dev/stderr
    fi
    for sl in ${SLAVES[@]} ; do
        if test -f "${BIN}/${sl}${ver}" ; then
            CMD="${CMD}    --slave ${BIN}/${sl} ${sl} ${BIN}/${sl}${ver}"
        else
            CMD="${CMD}    --slave ${BIN}/${sl} ${sl} /dev/null"
            echo "#  no ${BIN}/${sl}${ver}" > /dev/stderr
        fi
        if test -f "${MAN}/${sl}${ver}.1.gz" ; then
            CMD="${CMD}    --slave ${MAN}/${sl}.1.gz ${sl}.1.gz ${MAN}/${sl}${ver}.1.gz"
        else
            CMD="${CMD}    --slave ${MAN}/${sl}.1.gz ${sl}.1.gz /dev/null"
            echo "#  no ${MAN}/${sl}${ver}.1.gz" > /dev/stderr
        fi
    done

    if [[ -n ${DRYRUN} ]]; then
        echo -e ${REMCMD}
        echo -e ${CMD} | sed -e 's/\s* --slave/\n    --slave/g'
        echo "# Consider: update-alternatives --auto ruby"
    else
        ${REMCMD}
        ${CMD}
        echo "# Consider: update-alternatives --auto ruby"
    fi
done
r2evans
  • 191