6

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?

David Tuite
  • 22,258
  • 25
  • 106
  • 176
  • Are you running the script under the same user account, or with sudo or some such? – d11wtq Jan 11 '12 at 12:31
  • 1
    What happens when you type `/usr/bin/env ruby -v` at the prompt? – d11wtq Jan 11 '12 at 12:36
  • Weird.. on both systems (local and server) it works fine and outputs `ruby 1.9.3p0 (2011-10-30 revision 33570) ...`. So how come it can't find it when I run the script? – David Tuite Jan 11 '12 at 12:53
  • 2
    I can't explain that. Personally, RVM gives me the shits and I switched to rbenv a long time ago and never looked back. RVM screws with your shell quite extensively; rbenv is pretty much just a symlink trick. – d11wtq Jan 11 '12 at 12:56
  • Ok I figured something out. I think I'm mistakenly trying to run the script as the root user (as you suspected at the start). The root user has no access to ruby, eveidenced my the fact that when I `su` and run `/usr/bin/env ruby -v` I get the error: `/usr/bin/env: ruby: No such file or directory`. I think I need to ask a new question about how to make sure I run my script as the `dtuite` user. – David Tuite Jan 11 '12 at 14:51

1 Answers1

3

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

ezkl
  • 3,829
  • 23
  • 39
  • Sorry I had to un-accept this because what works yesterday doesn't seem to work today. [new question](http://stackoverflow.com/questions/8840742/cant-start-service-with-sudo-since-root-user-has-no-access-to-ruby) – David Tuite Jan 12 '12 at 19:04
  • Ok. I've decided to reaccept this answer because it essentially answers the question I asked. The fact that I asked the wrong question is not a valid reason to un-accept. – David Tuite Jan 12 '12 at 19:52
  • The link seems to be broken. – A.K. Dec 08 '15 at 09:23