How do I install ruby-rvm?

I want to install a rails environment on Ubuntu 11.04. I tried:

$ sudo apt-get install ruby-rvm

But got the error:

Unable to locate package ruby-rvm

My other PC has Ubuntu 11.10, and this works fine there:

$ sudo apt-get install ruby-rvm
$ rvm install ruby-1.9.3-p125
$ sudo gem update --system
$ sudo gem install rails

A simple way to install RVM is to follow the instructions at the developer's site (in fact, the site says "Please use the install process(es) from this site only, as this is the only supported installation types and methods."):

curl -L get.rvm.io | bash -s stable

Load RVM:

source ~/.rvm/scripts/rvm

Find the requirements (follow the instructions):

rvm requirements

Install ruby:

rvm install 1.9.3

On my system (12.04), this all went without a hitch; requirements listed were easy to find and install using apt-get.


Precise, Trusty, Xenial and higher

There is now an official Ubuntu package: https://github.com/rvm/ubuntu_rvm

Install

1. Add the PPA and install the package

Open a terminal (Ctrl+Alt+T) and run:

sudo apt-add-repository -y ppa:rael-gc/rvm
sudo apt-get update
sudo apt-get install rvm

Add your user to rvm group ($USER will automatically insert your username):

sudo usermod -a -G rvm $USER

2. Change your terminal window

Now, in order to always load rvm, change the Gnome Terminal to always perform a login.

At terminal window, click Edit > Profile Preferences, click on Command tab and check Run command as login shell.

enter image description here

3. Logout and login

A lot of changes were made and in order to properly get all them working, you need to login and logout. This requires not only close terminal window, but really logout and login again.

4. Install a ruby

Now you're ready to install rubies. Open a terminal (Ctrl+Alt+T) and run:

rvm install ruby

The ruby-rvm package is only present since Ubuntu 11.10. Furthermore, one of its dependencies, libreadline-gplv2-dev, only exists under this name since Ubuntu 11.10.

There is a version of ruby-rvm in the Canonical-SIG 3rd party testing PPA. It's for testing, so there may be bugs. See Add a Personal Package Archive (PPA) in the Ubuntu documentation for how to install software from a PPA.

You can grab the package source and compile it on your machine. Download the source from the Ubuntu 11.10 package page (you need all three files: .dsc, .orig.tar.gz and .debian.tar.gz). Install development tools and build dependencies, compile the package, install run-time dependencies and install the package.

wget http://archive.ubuntu.com/ubuntu/pool/universe/r/ruby-rvm/ruby-rvm_1.6.9-0ubuntu2.dsc http://archive.ubuntu.com/ubuntu/pool/universe/r/ruby-rvm/ruby-rvm_1.6.9.orig.tar.gz http://archive.ubuntu.com/ubuntu/pool/universe/r/ruby-rvm/ruby-rvm_1.6.9-0ubuntu2.debian.tar.gz
sudo apt-get install build-essential fakeroot debhelper ruby
dpkg-source -x ruby-rvm_1.6.9-0ubuntu2.dsc
cd ruby-rvm*
dpkg-buildpackage -rfakeroot -b -nc -us -uc
cd ..
apt-get install adduser bison curl file git libreadline5-dev libsqlite3-dev libxml2-dev zlib1g-dev
dpkg -i ruby-rvm_1.6.9-0ubuntu2_*.deb