Install ruby 2.0 without ruby-switch?

28,441

Solution 1

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

Solution 2

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.

Solution 3

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

Solution 4

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

Solution 5

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
Share:
28,441

Related videos on Youtube

aSteve
Author by

aSteve

Updated on September 18, 2022

Comments

  • aSteve
    aSteve over 1 year

    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
    aSteve about 10 years
    Is it really necessary to add a 'Personal Package Archive' in order to install Ruby 2.0 in Ubuntu 14.04 - given that there is a package for "Ruby2.0" available without?
  • Luis Alvarado
    Luis Alvarado about 10 years
    You asked for the most straightforward way. This would be it, at least until the official 2.x version of Ruby appears on the Software Center or until the Ruby 2.0.x version updates to the actual number that it is and not like the bug you got.
  • aSteve
    aSteve about 10 years
    Hmm... doesn't ubuntuupdates.org/package/core/trusty/main/base/ruby2.0 suggest that 2.0 is already included in the "main" repository?
  • Luis Alvarado
    Luis Alvarado about 10 years
    Yes but as you mentioned it is not the 2.x branch but the 1.9. So they should fix that.
  • aSteve
    aSteve about 10 years
    It looks as if both the 2.0 and 1.9 interpreters are in the main repository (with a weird dependency) - but ruby-switch has been deleted for a spurious reason.
  • Luis Alvarado
    Luis Alvarado about 10 years
    @aSteve I have the same thought. Weird. Maybe a mistake that will soon be fixed.
  • aSteve
    aSteve about 10 years
    Hmmm... When I installed the ruby2.0 package, I got a ruby2.0 executable and a ruby 1.9 executable. When interacting with gem, ruby1.9 seemed to be assumed as the system ruby version. On further investigation, I discovered that the scripts (while claiming to need ruby 2.0) actually run fine with ruby 1.9 - so I have abandoned the ruby2.0 package. I only wanted one ruby version - i.e. runy 2.0 - but the ubuntu 14.04 packages didn't seem to permit that.
  • Braiam
    Braiam about 10 years
    @aSteve in Debian I don't seem to have that problem, through Ubuntu uses that method. If you like, try creating a virtual environment for ruby 2.0 with rbenv instead, just to be on the safe side.
  • Josh Nankin
    Josh Nankin about 10 years
    i am definitely seeing that, and it makes no sense. on apt-get install ruby2.0 I get: The following NEW packages will be installed: libjs-jquery libruby1.9.1 libruby2.0 ruby ruby1.9.1 ruby2.0 rubygems-integration
  • Josh Nankin
    Josh Nankin about 10 years
  • Braiam
    Braiam about 10 years
    @JoshNankin come to the dark side cough Debian cough
  • jla
    jla over 9 years
    If Ruby does not support several ruby installations on the same system, why are the first two options for doing so at ruby-lang.org/en/installation/ rbenv and RVM which they say manage multiple ruby versions?
  • Braiam
    Braiam over 9 years
    @jla those are manual installations of Ruby, not using apt. Check ruby-lang.org/en/installation/#apt and it will tell you that they only provide 1 option. BTW, read the "Package Management Systems" section as well, specially "Certain members in the Ruby community feel very strongly that you should never use a package manager to install Ruby"
  • jla
    jla over 9 years
    @Braiam I think I'm still missing something. Are you saying "The Debian Ruby package does not support several ruby installations on the same system", because it seems that the Ruby suggested non-distro package installation tools support, and thus Ruby supports, multiple installations on the same system.
  • Braiam
    Braiam over 9 years
    @jla no, actually, Debian chooses not to support several versions of Ruby, as you can see in the changelog. Debian says it will support just one version and the tools to switch versions are somehow broken, that's more or less the situation in Debian. Ubuntu decided not to make the leap for 2.0 at that time.
  • muru
    muru about 9 years
    IIRC you can just call ${RECMD} and ${CMD} without quotes, instead of using eval. On another note: I'll be borrowing "kludgingly". :)
  • r2evans
    r2evans about 9 years
    True ... it was a near-hasty hack. Fixed. Thanks :-)
  • njzk2
    njzk2 over 8 years
    you can also ln -fs to force the update and avoid using the always scary rm -rf