Difference between revisions of "RVM"
m (Extra newline) |
m (" don't " -> " do not ") |
||
Line 4: | Line 4: | ||
=== Installing RVM === | === 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). If you | + | 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). If you do not know which to choose, start with a single user installation. |
The upstream instructions for installing RVM should just work. The install script is aware enough to tell you what packages you need to install on Archlinux to make different rubies work. This usually involves gcc and some other stuff needed to compile ruby. | The upstream instructions for installing RVM should just work. The install script is aware enough to tell you what packages you need to install on Archlinux to make different rubies work. This usually involves gcc and some other stuff needed to compile ruby. | ||
Line 149: | Line 149: | ||
=== Troubleshooting === | === Troubleshooting === | ||
− | You'll need to take care with rvm installations, since ArchLinux is very well updated, and some earlier ruby's patchlevels | + | You'll need to take care with rvm installations, since ArchLinux is very well updated, and some earlier ruby's patchlevels do not like it. RVM many times do not choose the latest patchlevel version to install, and you'll need to check manually on the [http://www.ruby-lang.org/en/news/ ruby website], and force RVM to install it. |
==== "data definition has no type or storage class" ==== | ==== "data definition has no type or storage class" ==== | ||
Line 182: | Line 182: | ||
==== Ruby 1.9.1 won't compile with RVM ==== | ==== Ruby 1.9.1 won't compile with RVM ==== | ||
− | Like with 1.8.x, earlier patchlevels | + | Like with 1.8.x, earlier patchlevels do not like the OpenSSL 1.0. Then you can use the very same solution above, by installing openssl locally on RVM. |
$ rvm pkg install openssl | $ rvm pkg install openssl |
Revision as of 23:14, 3 October 2011
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.
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). If you do not know which to choose, start with a single user installation.
The upstream instructions for installing RVM should just work. The install script is aware enough to tell you what packages you need to install on Archlinux to make different rubies work. This usually involves gcc and some other stuff needed to compile ruby.
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
Before we start, we'll need the following to get the installation process going:
$ pacman -S git curl
User installation
We will use the script that rvm docs recommends to install. Make sure to run this script as the user for whom you want RVM installed (i.e. your normal user that you use for development).
$ bash < <( curl -s https://rvm.beginrescueend.com/install/rvm )
If instead you want to check the script before running it, do:
$ curl -L https://rvm.beginrescueend.com/install/rvm > rvm-install
Inspect the file, then run it with:
$ bash < ./rvm-install
After the script has finished, then add the following line to the end of your ~/.bash_profile or ~/.bashrc (or ~/.zprofile or whatever):
$ [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
System-wide installation
System-wide installation is a similar procedure to the single user install. However, instead we run the install script as root. Become root, then do:
# bash < <( curl -L https://rvm.beginrescueend.com/install/rvm )
After the script has finished, there should be a script called rvm.sh in /etc/profile.d/ that configures the rvm environment. By default, /etc/profile should include it. To setup the rvm environment without logging out, use
. /etc/profile.d/rvm.sh
To avoid using rvm.sh, you will need to add
[[ -s '/usr/local/rvm/scripts/rvm' ]] && source '/usr/local/rvm/scripts/rvm'
to the necessary user's ~/.bash_profile or ~/.bashrc (or ~/.zprofile or whatever).
Post installation
After the installation, check everything worked with this command:
$ type rvm | head -n1
The response should be:
$ rvm is a function
If you receive rvm: not found, you may need to source your .bash_profile (or wherever you put the line above):
$ . ~/.bash_profile
Check if the rvm function is working:
$ rvm notes
Using RVM
The RVM documentation is quite comprehensive and explanatory. However, here are some RVM usage examples to get you started.
Installing an environment
To see what Ruby environments are available to install, run:
$ rvm list known
To install one, run:
$ rvm install
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 in the place you installed RVM. For example, if you did a single user install, it will be in ~/.rvm/rubies/1.8.7.
Switching Environment
To switch from one environment, to another simply run:
$ rvm use
For example to switch to Ruby 1.8.7 one would run the following command:
$ rvm 1.8.7
You should get a message telling you the switch worked. It can be confirmed by running:
$ ruby --version ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-linux]
Note that this environment will only be used in the current shell. You can open another shell and select a different environment for that one in parallel. Also, the default environment will be the system ruby in /usr. This can be changed using RVM if you wish; for more details consult the RVM documentation.
Listing Ruby Environments
To see all installed Ruby environments, run the following command:
$ rvm list
If you've installed a few rubies, this might generate a list like so:
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]
RVM update
Simply use:
$ rvm update
Revert the default ruby to system ruby
If you want to use the system ruby, i.e. the one installed in /usr by the standard Archlinux package, run
$ rvm use system
Further Reading
This is just a simple introduction to switching ruby versions with RVM. There is lots more that you can do with it, including managing different set of gems in different environments. For more information, consult the very comprehensive RVM documentation. This page is a good place to start.
Troubleshooting
You'll need to take care with rvm installations, since ArchLinux is very well updated, and some earlier ruby's patchlevels do not like it. RVM many times do not choose the latest patchlevel version to install, and you'll need to check manually on the ruby website, and force RVM to install it.
"data definition has no type or storage class"
This appears to be specific to 1.8.7, but if you get this error while compiling the following steps will fix your problem:
$ cd src/ruby-1.8.7-p334/ext/dl $ rm callback.func $ touch callback.func $ ruby mkcallback.rb >> callback.func $ rm cbtable.func $ touch cbtable.func $ ruby mkcbtable.rb >> cbtable.func
Naturally, substitute the actual build path to your source, which will be something like ~/.rvm/src/.
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 pkg install openssl $ rvm remove 1.8.7 $ rvm install 1.8.7 -C --with-openssl-dir=$HOME/.rvm/usr
Ruby 1.9.1 won't compile with RVM
Like with 1.8.x, earlier patchlevels do not like the OpenSSL 1.0. Then you can use the very same solution above, by installing openssl locally on RVM.
$ rvm pkg install openssl $ rvm remove 1.9.1 $ rvm install 1.9.1 -C --with-openssl-dir=$HOME/./rvm/usr
The patchlevels >p378 have a problem with gem paths, when $GEM_HOME is set. The problem is known and fixed in 1.9.2. (http://redmine.ruby-lang.org/issues/3584). If you really need 1.9.1 please use p378.
$ rvm install 1.9.1-p378 -C --with-openssl-dir=$HOME/./rvm/usr