|NOTE: Before running the commands shown on this page, you should load the Bitnami stack environment by executing the installdir/use_APPNAME script (Linux and Mac OS X) or by clicking the shortcut in the Start Menu under "Start -> Bitnami APPNAME Stack -> Application console" (Windows). Learn more.|
Ruby enVironment Manager (RVM) is a command-line tool which allows you to easily install, manage, and work with multiple Ruby environments from interpreters to sets of gems.
How to load RVM?
To use RVM interactively, load it in an interactive shell, as below:
$ cd installdir $ ./rubyconsole
How to list the available gemsets for a given Ruby version?
RVM allows you to define multiple groups of gems (gemsets) for your RVM-managed Rubies. This is specially useful in those applications not managed using Bundler.
Select an installed Ruby using:
$ rvm use 1.9.3
Then, get the list of defined gemsets by executing:
$ rvm gemset list gemsets for ruby-1.9.3-p194 (found in /opt/rubystack-3.2.3-0/rvm/gems/ruby-1.9.3-p194) global project-sample
In this example, two gemsets are available, global (the default gemset with the gems that are available to all other gemsets) and project-sample, a custom gemset created for a sample project.
How to create a gemset?
To create a new gemset, execute a command like the one below:
$ rvm gemset create GEMSET-NAME
How to select a gemset for a given Ruby version?
To select a gemset for a given Ruby version, use this command:
$ rvm gemset use GEMSET-NAME
How to share gems between all the gemsets?
RVM defines a global gemset which is shared among all the gemsets for a specific Ruby version. To install a shared gem, execute:
$ rvm gemset use global $ gem install rails $ rvm gemset use GEMSET-NAME $ gem list rails
How to list the installed Ruby versions?
To list the currently installed Ruby versions, execute:
$ rvm list rvm rubies # No rvm rubies installed yet. Try 'rvm help install'.
As the message states, if no Ruby version is installed, the list will be empty. After installing, the output will change to the below:
$ rvm list rvm rubies ruby-1.9.1-p431 [ i386 ] =* ruby-1.9.2-p320 [ i386 ] # => - current # =* - current && default # * - default
How to select a Ruby from the list of installed versions?
Changing the Ruby interpreter being used is as easy as executing:
$ rvm use ruby-1.9.2-p320
to use Ruby 1.9.2 (for example).
To verify the result, execute:
$ rvm list rvm rubies * ruby-1.9.1-p431 [ i386 ] => ruby-1.9.2-p320 [ i386 ] # => - current # =* - current && default # * - default
$ ruby --version ruby 1.9.2p320 (2012-04-20 revision 35421) [i386-darwin11.2.0]
It is also possible to use the system Ruby (the main Ruby installed with the Bitnami stack, not through RVM) by executing:
$ rvm use system Now using system ruby.
How to install a new Ruby version?
You can get the list of all the available Ruby versions by invoking:
$ rvm list known
This will print a list like:
... # MRI Rubies ... [ruby-]1.8.7-head [ruby-]1.9.1[-p431] [ruby-]1.9.2[-p320] ... [ruby-]1.9.3-[p194] [ruby-]1.9.3-head ruby-head
To install a new Ruby from the list (eg. ruby-1.9.1-p431), execute:
$ rvm install ruby-1.9.1-p431
RVM will take care of downloading, unpacking and compiling the requested Ruby.
You may not find the Ruby version that you are looking for if using an outdated version of RVM. Use the following command to first update your list of available versions:
$ rvm get stable
How to uninstall an existing Ruby version?
You can uninstall an existing RVM-managed Ruby version by executing:
$ rvm uninstall ruby-1.9.1-p431
|NOTE: When running the commands shown on this page, replace the installdir placeholder with the full installation directory for your Bitnami stack.|
What is RVM?
RVM (Ruby enVironment Manager) is a command-line tool which allows you to easily install, manage, and work with multiple Ruby environments from interpreters to sets of gems.
Every installed Ruby using RVM is isolated in its own directory with its libraries and gems. This is convenient if you need to maintain multiple projects, dependent on different Ruby versions.
RVM also has a very flexible gem management system called "named gemsets". These gemsets allows defining independent groups of gems, which is really convenient to maintain multiple projects with different set of gems. This is partially addressed by Bundler, but while Bundler just takes care of installing and selecting the appropriate Gem version, RVM completely isolate the gem sets into its own GEM_PATH. Also, not all your applications will be compatible with Bundler. It is also possible to use a combination of both, which will make sure you won't get in any trouble when working with different gem requirements.
Because of the above mentioned features, RVM is a perfect asset for your development process but that does not mean it is not suitable for production environments thanks to its ability to make setting up rubies / gems very efficient. It will also allow you to test your application in multiple Ruby versions so you will have a consistent environment from development, through testing, and into production.
To make use of RVM, you must have a compilation environment set up in your machine. You will need this compilation environment mostly to compile new Ruby versions but it will be also needed to compile some gems such as nokogiri.
Find a detailed list of the packages to install by executing:
$ rvm requirements
This will include more packages than really necessary as the Bitnami Ruby Stack already includes most of the required libraries.
Execute the command below to install the minimum list of required packages:
$ sudo apt-get install build-essential autoconf automake libtool bison
Mac OS X
There are multiple ways of setting up the required environment in Mac OS X:
Install Xcode 4.1: This is the preferred way. There is no problems with using this version with the compilation of Rubies and the native gems.
Use osx-gcc-installer from Kenneth Reitz: This is a stripped down version of Xcode 4.1, which only includes GCC and the required libraries. The limitation of this solution is that it does not include certain headers, such as the Carbon/Cocoa headers, which are found in the main Xcode install (because of license restrictions from Apple). This means that some native gems will fail to compile. You could still get the header packs from Apple but you will have to be a registered Apple Developer.
Use Xcode 4.2+: These versions of Xcode use a non-compatible version of GCC. If you want to use them, you will need to start installing Xcode 4.1, and then upgrade, answering not to them when asked to remove prior versions. Then you will have to use /usr/bin/gcc-4.2 to compile.
How to tweak RVM?
Enabling a per-project .rvmrc
This feature allows developers to define project-specific settings such as the Ruby version and dems to use. Those settings will be loaded when entering the project directory.
To enable this feature, follow these steps:
Edit the file installdir/rvm/.rvmrc and change the property rvm_project_rvmrc=0 to rvm_project_rvmrc=1. The result will be similar to the output below:
export rvm_project_rvmrc=1 export rvm_bin_path="/home/bitrock/rubystack-3.2.3-0/rvm/bin" export rvm_usr_path="/home/bitrock/rubystack-3.2.3-0/common" export rvm_patch_names="osx-arch-fix" export rvm_path="/home/bitrock/rubystack-3.2.3-0/rvm" export rvm_prefix="/home/bitrock/rubystack-3.2.3-0"
After enabling this feature, when entering a directory containing an .rvmrc file, you will receive a warning message asking for permissions to use the .rvmrc file:
==================================================================================== = NOTICE = ==================================================================================== = RVM has encountered a new or modified .rvmrc file in the current directory = = This is a shell script and therefore may contain any shell commands. = = = = Examine the contents of this file carefully to be sure the contents are = = safe before trusting it! ( Choose v[iew] below to view the contents ) = ==================================================================================== Do you wish to trust this .rvmrc file? (/home/bitrock/rubystack-3.2.3-0/rvm/.rvmrc) y[es], n[o], v[iew], c[ancel]>
If you know the contents of the file and that it is safe, accept. You will receive this message every time a new .rvmrc file is found or when a known .rvmrc file changes.
Change into the project directory and use rvm to create the sample .rvmrc file. For example, if you want to use Ruby 1.9.3 with the gemset bitrock-sample, use thse commands:
$ cd /home/bitrock/projects/rubystack-3.2.3-0 $ rvm --rvmrc --create 1.9.3@bitrock-sample
Leave and re-enter the directory. You will be prompted as above and the configured environment will be loaded. To manually trust the new .rvmrc file, execute this command:
$ rvm rvmrc trust