Installing Ruby(s) on an Unprivileged Account

Ruby's way of dealing with libraries and packages is "gems." More than any other language I've encountered, the Ruby community doesn't seem to be keen on A) stability, or B) consistency. So an app that runs with Ruby 2.1 and Nokogiri 1.6.4 may be completely broken with Ruby 2.1.5 and Nokogiri 1.6.6.2. This has led to a complex requirements and bundling system that mean it's much better/more practical to install your own private Ruby than attempt to use the system Ruby. It's not an arrangement I like, but I kind of get it and have come to appreciate RVM as a solution to a problem I don't think should exist.


This is mostly derived from https://rvm.io/rvm/install .

Get the Ruby Version Manager GPG key into your keychain:

$ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3

Something the RVM site doesn't mention, or at least not on the front page, is that you're really going to need most of Linux's dev toolchain, so run something like this:

# apt-get install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libxml2-dev autoconf libc6-dev ncurses-dev automake libtool libgmp-dev

(This list hasn't been vetted by me, I just grabbed it after the fact from a stackoverflow answer. But I appended libgmp-dev so you won't encounter the problem I mentioned later.)

Grab their shell script and pipe it through Bash, which creates a ~/.rvm folder and puts various stuff in it:

$ \curl -sSL https://get.rvm.io | bash

Not sure what all this command does, but its most immediate and practical use is to put ~/.rvm/bin/ on your path so you can type rvm and actually get a functional response:

$ source .rvm/scripts/rvm

Check the available versions of Ruby:

$ rvm list known
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.8]
[ruby-]2.2[.4]
[ruby-]2.3[.0]
[ruby-]2.2-head
ruby-head

# for forks use: rvm install ruby-head-<name> --url https://github.com/github/ruby.git --branch 2.2

# JRuby
jruby-1.6[.8]
jruby-1.7[.23]
jruby[-9.0.5.0]
jruby-head

# Rubinius
rbx-1[.4.3]
rbx-2.3[.0]
rbx-2.4[.1]
rbx[-2.5.8]
rbx-head

# Opal
opal

# Minimalistic ruby implementation - ISO 30170:2012
mruby[-head]

# Ruby Enterprise Edition
ree-1.8.6
ree[-1.8.7][-2012.02]

# GoRuby
goruby

# Topaz
topaz

# MagLev
maglev[-head]
maglev-1.0.0

# Mac OS X Snow Leopard Or Newer
macruby-0.10
macruby-0.11
macruby[-0.12]
macruby-nightly
macruby-head

# IronRuby
ironruby[-1.1.3]
ironruby-head

For my purposes, MRI Ruby (which is also the default) is the best choice. So:

$ rvm install 2.3

This demanded my password because it wanted to run apt-get, so I had to Ctrl-C out. No explanation was offered as to what was missing. To get an explanation:

$ rvm install 2.3 --autolibs=fail

Reading through the cruft, it turns out the system I was working on was missing libgmp-dev. This was installed as root, after which this worked:

$ rvm install 2.3

So, despite my initial claim, privilege was required for this. Had my system been better equipped initially, this wouldn't have been needed. Now:

$ ruby --version
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]

Not strictly part of what I advertise with the title of this blog entry, but very likely something you'll want:

$ gem install bundler