rvmrc files
There are 3 types of rvmrc files, system user and project. They are discussed in detail below.
System /etc/rvmrc
The system rvmrc file is loaded before RVM initializes and before the user's ~/.rvmrc. /etc/rvmrc settings are applied to all users on the system.
User $HOME/.rvmrc
The users rvmrc file overwrites settings in /etc/rvmrc and is loaded before RVM initializes. $HOME/.rvmrc settings are applied only for the user belonging to $HOME.
System / User rvmrc examples
Have RVM install rubies when used instead of simply displaying a warning and exiting.
rvm_install_on_use_flag=1
Have RVM compile using say, 3, compile threads.
rvm_make_flags="-j 3"
Have RVM install to a different location (notice that it ends with /rvm).
rvm_path=/opt/rvm
Have RVM compile rubies and libraries as x86_64 on *Mac OS X*.
rvm_archflags="-arch x86_64"
Similarly for i386 on *Mac OS X*.
rvm_archflags="-arch i386"
More examples may be found in ~/.rvm/examples/rvmrc.
Project .rvmrc
The project .rvmrc file is different than the system & user. System & user rvmrc files are meant for altering the settings and behavior of RVM. The project rvmrc files are intended to be used to setup your project's ruby environment when you switch to the project root directory.
If you are using the latest version of RVM (rvm update --head) then you can take advantage of a few new features, namely hooks and the new project specific ‘.rvmrc’ file. (Available in RVM 0.0.85+)
Let’s say I have my project directory as ~/projects/ and in this directory I have three projects 'projecta', 'projectb', and 'projectc'. Project a runs on jruby, project b runs on ree 1.8.7, and project c runs on 1.9.1. The setup:
mkdir -p ~/projects/projecta ~/projects/projectb ~/projects/projectc echo "rvm jruby@projecta" > ~/projects/projecta/.rvmrc echo "rvm ree@projectb" > ~/projects/projectb/.rvmrc echo "rvm 1.9.1@projectc" > ~/projects/projectc/.rvmrc
Then if I type this:
cd ~/projects/projecta [jruby-1.4.0] ∴ ruby -v jruby 1.4.0 (ruby 1.8.7 patchlevel 174) (2009-11-02 69fbfa3) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_15) [x86_64-java] [jruby-1.4.0] ∴ gem env gemdir /Users/wayne/.rvm/gems/jruby/1.4.0@projecta
I will then be running jruby with 'projecta' gemset and we see that the prompt is now prefixed with '[jruby-1.4.0]'.
Now if we change to project b's directory.
cd ~/projects/projectb [ree-1.8.7-2009.10] ∴ ruby -v ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10.2.0], MBARI 0x6770, Ruby Enterprise Edition 2009.10 [ree-1.8.7-2009.10] ∴ gem env gemdir /Users/wayne/.rvm/gems/ree/1.8.7
We see that we are now running ree with a 'projectb' gemset and we see that the prompt is now prefixed with '[ree-1.8.7-2009.10]'.
Finally we change to project c's directory.
cd ~/projects/projectc [ruby-1.9.1-p243] (0) ∴ ruby -v ruby 1.9.1p243 (2009-07-16 revision 24175) [i686-darwin10.2.0] [ruby-1.9.1-p243] (0) ∴ ruby -v /Users/wayne/.rvm/gems/ruby/1.9.1@projectc
We see that we are now running ree with a 'projectb' gemset and we see that the prompt is now prefixed with '[ruby-1.9.1-p243]'.
Note that the project .rvmrc file is simply a shell script and may contain any shell commands necessary for you to initialize your project's environment.
To turn off the project specific rvmrc functionality in your $HOME/.rvmrc set
rvm_project_rvmrc=0
To enable switching to default / system when leaving a directory set
rvm_project_rvmrc_default=1
Warning
Do NOT use shell commands in the System and User rvmrc files. For example do not put 'rvm ree' or any other such commands in these two rvmrc files. They are for setting environment variables only to modify RVM's behavior and settings.