Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I reference the local ruby in a hash-bang executable?

I have a Ruby executable (it's a bundler binstub) which starts with

#!/usr/bin/env ruby

On my server I have Ruby 193 installed via RVM.

$ which ruby
-> /home/dtuite/.rvm/rubies/ruby-1.9.3-p0/bin/ruby

On my local machine, I also have Ruby installed via RVM, but in a different location (obviously!)

$ which ruby
-> /Users/davidtuite/.rvm/rubies/ruby-1.9.3-p0/bin/ruby

When I try to run this executable on the server I get an error

/usr/bin/env: ruby: No such file or directory

Is there a way I can reference the locally available ruby in the hash-bang so that the same script will execute on both the server and the local machine?

like image 910
David Tuite Avatar asked Jan 11 '12 12:01

David Tuite


People also ask

What is a shebang Ruby?

The opening line is called a shebang because of the first two characters #! . This line provides the shell (in our case, bash) with the absolute path to the Ruby interpreter. If we were writing a script in another language, we'd provide the path to that interpreter instead.

What is usr bin env Ruby?

#!/usr/bin/env ruby. ...uses the PATH to look up the location of the ruby executable. Because the path to the env executable is fully specified, this is a valid shebang line (which #! ruby is not).


1 Answers

Try rvm-auto-ruby - it is explained in a somewhat different context in RVM's Textmate documentation.

like image 54
ezkl Avatar answered Oct 03 '22 06:10

ezkl