Difference between revisions of "RVM"

From ArchWiki
Jump to: navigation, search
m (Pre-requisites: don't use pacman -Sy pkg, use -S or -Syu)
m (Post installation)
Line 56: Line 56:
  
 
  $ rvm notes
 
  $ rvm notes
 
  
 
=== Using RVM ===
 
=== Using RVM ===

Revision as of 02:20, 12 September 2010

RVM (Ruby Version Manager) is a command line tool which allows us to easily install, manage and work with multiple Ruby environments from interpreters to sets of gems.

Note: These instructions bypass pacman.

Installing RVM

The install process is very easy, and is the very same for any distro, including ArchLinux. You have two choices, one system-wide, another as a user. The first is for production servers, or if your are alone on your machine. You'll need root privileges. The second is the recommended for multiple users on the same machine (like a development test box).

As an observation, installing RVM with gem is not recommended anymore. This article uses the recommended documentation with minor tweaks to make work on ArchLinux.

Pre-requisites

$ pacman -S git curl

System-wide installation

First we will use the script that rvm docs recommends to install:

$ bash < <( curl -L http://github.com/wayneeseguin/rvm/raw/master/contrib/install-system-wide )

If you want to check the script before:

$ curl -L http://bit.ly/rvm-install-system-wide > rvm-install-system-wide

Inspect the file here, then:

$ bash < ./rvm-install-system-wide

After the script process, add this to the last line of /etc/bash.bashrc

$ [[ -s '/usr/local/lib/rvm' ]] && source '/usr/local/lib/rvm'

Now go to post-installation procedures.

User installation

User-wide installation have a similar procedure to the system-wide install:

$ bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )

Then add to your ~/.bash_profile or ~/.bashrc:

$ [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

Post installation

After the installation, check with this command:

$ type rvm | head -n1

The response should be:

$ rvm is a function

Check if the rvm function is working:

$ rvm notes

Using RVM

Here's some RVM usage examples, for general usage no more is needed.

Installing an environment

To install a Ruby environment, run:

$ rvm install <environment/ruby version>

For example, to install Ruby 1.8.7 one would run the following command:

$ rvm install 1.8.7

This should download, configure and install Ruby 1.8.7. Make sure, you have gcc or another fitting compiler installed.

Listing Ruby Environments

To see all available Ruby environments, run the following command:

$ rvm list

This would generate a list like so:

~> rvm list
rvm Rubies
   jruby-1.5.0 [ [i386-java] ]
=> ruby-1.8.7-p249 [ i386 ]
   ruby-1.9.2-head [ i386 ]
System Ruby
   system [ i386 ]

The ASCII arrow indicates which environment is currently enabled. In this case, it is Ruby 1.8.7. This could be confirmed by running:

$ ruby --version
ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-linux]

Switching Environment

To switch from one environment, to another simply run:

$ rvm <version/environment>

For example to switch to Ruby 1.8.7 one would run the following command:

$ rvm 1.8.7

It can be confirmed by running:

$ ruby --version
ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-linux]

RVM update

Simply use:

$ rvm update

Revert the default ruby to system ruby

$ rvm system

And check if the version complies with your system installed package:

$ ruby -v
$ pacman -Q ruby
$ which ruby

"which ruby" must be pointing to /usr/bin/ruby

Troubleshooting

You'll need to take care with rvm installations, since ArchLinux is very well updated, and some earlier ruby's patchlevels don't like it. RVM many times don't choose the latest patchlevel version to install, and you'll need to check manually on the ruby website, and force RVM to install it.

Ruby 1.8.x won't compile with RVM

This is a known issue on Arch Linux, and is caused by a problem with openssl. Arch uses openssl 1.0, lower patchlevels of 1.8.7 assumes 0.9.

You can use newer patchlevels, like p299 or newer with:

$ rvm remove 1.8.7
$ rvm install 1.8.7-p299

Another approach is to install local openssl via RVM:

$ rvm package install openssl
$ rvm remove 1.8.7
$ rvm install 1.8.7 -C --with-openssl-dir=$HOME/.rvm/usr

Ruby 1.9.x won't compile with RVM

Like with 1.8.x, earlier patchlevels don't like the OpenSSL 1.0. Then you can use the very same solution above, by installing openssl locally on RVM.

$ rvm package install openssl
$ rvm remove 1.9.1
$ rvm install 1.9.1 -C --with-openssl-dir=/usr/local/rvm/usr