I would like ruby scripts with the header #! /usr/bin/ruby
to execute using the currently in use rvm version of ruby. I run into the issue where I am using a given version but upon executing the script the system ruby is invoked. Installing RVM for every user on the system is not an option.
Problem:
ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.3.0]
/usr/bin/ruby -v
ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]
How to make it the following without performing a system wide install of RVM?
ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.3.0]
ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.3.0]
If you do which ruby
, you'll find that RVM's ruby
does not lie at /usr/bin/ruby
. Instead use:
#!/usr/bin/env ruby
This will tell it to look up which ruby
to use in the current environment (essentially the $PATH
).
You could also execute your script via ruby
itself: ruby myscript.rb
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With