Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executable Ruby Scripts Using the Current Local User RVM Install?

Tags:

ruby

rvm

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]
like image 463
rudolph9 Avatar asked Mar 06 '12 00:03

rudolph9


1 Answers

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

like image 81
Andrew Marshall Avatar answered Oct 10 '22 21:10

Andrew Marshall