1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

Using Rubies

By

Now that you've installed a Ruby or two, it's time to start using them. First, list which Rubies you have installed using the rvm list command. This will list the Rubies installed, if you have many installed you should run it often to remind yourself of their shortened names.

Once you have the name of a Ruby you'd like to switch to, use the rvm use command. It takes a single parameter, name of the Ruby to use. If everything went well, you should get a green status message.

$ rvm use 1.8.6
Using ruby 1.8.6 p399

To be sure you're really going to be using this Ruby, give the command which ruby a try. This isn't an RVM command, it's a system command on Linux and OSX that will tell you from what path the command ruby will be run. It should give you a path within your home directory, inside the .rvm directory.

$ which ruby
/home/user/.rvm/rubies/ruby-1.8.6-p399/bin/ruby

But you don't have to run your programs with the ruby command, you can run them as you normally would. How does this work? Well, when a file is executable, the first line is the "shebang" line. The shebang line on a Ruby script should read #!/usr/bin/env ruby. Notice it's not calling the Ruby executable directory, it's calling env, which will dynamically find where Ruby is (just like which did). If your programs have a different shebang line, consider changing them or run them with the ruby command from the command line.

The other Ruby commands automatically switch over to your new Ruby as well. So, if you switch to 1.9.1, your irb and ri command will use the new Ruby as well.

Note that the new Ruby is used for that shell only, it isn't system-wide. This can be used to your advantage. For example, you can open two terminal windows and have 1.8.7 in one, and 1.9.1 in the other.

  1. About.com
  2. Technology
  3. Ruby
  4. Advanced Ruby
  5. Ruby Version Manager
  6. Using Rubies

©2014 About.com. All rights reserved.