my ruby prog:

while 1 < 2
  puts "hey!"

the bash(?) script that calls it:

ruby -v
ruby echoHW.rb "$@" & 

I installed rvm, trying both "single user" and "multi user" modes; I have my default set to 1.9.3p125, but no matter what I do, when I run this, it runs 1.8.7, which evidently is the "system" version of ruby.

I'm guessing this is an easy fix -- I want the script to call the ruby I set as default with RVM -- but I'm stumped.


EDIT: the output of rvm info:

qe2user@qe2server:~/Ruby/query_engine$ rvm info


system: uname: "Linux qe2server 2.6.32-33-server #70-Ubuntu SMP Thu Jul 7 22:28:30 UTC 2011 x86_64 GNU/Linux" bash: "/bin/bash => GNU bash, version 4.1.5(1)-release (x86_64-pc-linux-gnu)" zsh: " => not installed"

rvm: version: "rvm 1.12.3 (stable) by Wayne E. Seguin , Michal Papis [htps://rvm.io/]" updated: "13 hours 39 minutes 42 seconds ago"

ruby: interpreter: "ruby" version: "1.9.3p125" date: "2012-02-16" platform: "x86_64-linux" patchlevel: "2012-02-16 revision 34643" full_version: "ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-linux]"

homes: gem: "/usr/local/rvm/gems/ruby-1.9.3-p125" ruby: "/usr/local/rvm/rubies/ruby-1.9.3-p125"

binaries: ruby: "/usr/local/rvm/rubies/ruby-1.9.3-p125/bin/ruby" irb: "/usr/local/rvm/rubies/ruby-1.9.3-p125/bin/irb" gem: "/usr/local/rvm/rubies/ruby-1.9.3-p125/bin/gem" rake: "/usr/local/rvm/gems/ruby-1.9.3-p125@global/bin/rake"

environment: PATH: "/usr/local/rvm/gems/ruby-1.9.3-p125/bin:/usr/local/rvm/gems/ruby-1.9.3-p125@global/bin:/usr/local/rv /rubies/ruby-1.9.3-p125/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games" GEM_HOME: "/usr/local/rvm/gems/ruby-1.9.3-p125" GEM_PATH: "/usr/local/rvm/gems/ruby-1.9.3-p125:/usr/local/rvm/gems/ruby-1.9.3-p125@global" MY_RUBY_HOME: "/usr/local/rvm/rubies/ruby-1.9.3-p125" IRBRC: "/usr/local/rvm/rubies/ruby-1.9.3-p125/.irbrc" RUBYOPT: "" gemset: ""

  • What's the output of rvm info on your system?
    – CodeGnome
    Apr 18, 2012 at 2:05
  • @CodeGnome: Just added that to orig post
    – davej
    Apr 18, 2012 at 12:39

1 Answer 1


It doesn't sound like you've set your default Ruby interpreter properly under RVM. For example, with a properly-installed RVM:

# Assumes that 1.9.3-p125 is already fully-installed under RVM.
rvm --default use ruby-1.9.3-p125

This will ensure that the specified Ruby is used, rather than the system default. You can change the current Ruby anytime with rvm use at the shell prompt.

If you want to use something other than the default from within a script, though, you could wrap your script with another shell script that sets the current Ruby using RVM. If that isn't an option, you can also call a specific interpreter directly on your shebang line:


but this may also require you to mangle some environment variables, such as MY_RUBY_HOME and RUBY_VERSION (see rvm info for a complete list) in order to get various libraries and gems to work.

Modifying the environment may or may not be necessary for you--a lot depends on what your Ruby script is doing--but if it is necessary, you can play with various options on the command line until you get everything working together. For example:

$ MY_RUBY_HOME=~/.rvm/rubies/ruby-1.9.3-p125 \
    ~/.rvm/rubies/ruby-1.9.3-p125/bin/ruby -e 'puts("hello")'

Also, read up on project .rvmrc files. This is another avenue to ensure that your working environment is using the Ruby and gemset you need for your particular application.

  • I realize I was unclear in the original post. "bash script.sh" works fine, but "sudo bash script.sh" does not, it tells me "command not found" for ruby. Thank you for your input, and if you have any other suggestions, I'd appreciate it.
    – davej
    Apr 18, 2012 at 20:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .