Tutorial and Examples on how to Use RVM on Linux

Tutorial and Examples on how to Use RVM on Linux

Last updated:

Installation

  • download the gpg keys:

    $ command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
    
  • download RVM proper:

    $ curl -L https://get.rvm.io | bash -s stable
    
  • "activate" RVM:

    $ source ~/.rvm/scripts/rvm
    

Hint: Activation only lasts for the current terminal session. To make this permanent, you need to add it to your shell startup files (you need to close and then reopen your terminal for it to take effect)

$ echo "source ~/.rvm/scripts/rvm" >> ~/.bashrc

Show available ruby versions

$ rvm list known

Download specific ruby versions

$ rvm install 2.0.0
$ rvm install 1.9.3

Switch ruby versions

$ rvm use 2.0.0

Run ruby scripts as SUDO

using regular sudo messes up with the way RVM adapts your system to use different version of ruby, so use RVM special rvmsudo if you need sudo access.

For example, to the version of gem for the root user using the currently activated ruby version:

$ rvmsudo gem -v

Set a default version

(only if you've previously installed it, obviously)

$ rvm --default use 1.9.2

Run Shell scripts (shebang)

You can do everything everything you normally do, but make sure to use this shebang:

#!/usr/bin/env ruby

Troubleshooting

  • RVM is not a function, selecting rubies with 'rvm use ...' will not work.. You must set your shell to work as a login shell. (On Ubuntu, go to Edit->Profile Preferences->Title and Command-> Run command as a login shell). For more information, see this.

  • If you make a mistake and want to remove all currently installed gems for the current gemset, you can do it via

    $ rvm gemset empty