How to get /usr/bin/env ruby to point to the correct ruby environment?

Tags:

Answer: 1

24 hours ago

So I was making a cgi ruby script and had the following at the top of the script file:

#!/usr/bin/env ruby
 require 'rubygems'
 require 'action_pack'
 require 'cgi'

After a couple of hours of not getting "/usr/bin/env: ruby: No such file or directory" error and google searching, I uninstalled my system ruby 1.8.7 (I also had 1.9.3 installed via rvm) by doing sudo apt-get purge ruby rubygems. I still get the error. When I type "which ruby", I get /home/homeuser/.rvm/rubies/ruby-1.9.3-p194/bin/ruby. Does anyone have any insight as to how to fix this problem?

Here is what echo $PATH yields:

/home/homeuser/.rvm/gems/ruby-1.9.3-p194@rsoc326/bin:/home/homeuser/.rvm/gems/ruby-1.9.3-p194@global/bin:/home/homeuser/.rvm/rubies/ruby-1.9.3-p194/bin:/home/homeuser/.rvm/bin:/var/lib/gems/1.8/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/homeuser/.rvm/bin

I have this same setup on my desktop and I don't have the same issue.

Added by: Judge Stoltenberg

Answer: 2

3 hours ago

/usr/bin/env ruby should be pointing to the RVM ruby.

But lets check your setup

  1. Check the contents of your ~/.profile, it should contain something like these 2 lines:

    export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
    [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"  # This loads RVM
    
  2. Second, check your installed ruby version:

    rvm list
    

    this should output something like the following:

    rvm rubies
    
    =* ruby-1.9.3-p286 [ x86_64 ]
    
    # => - current
    # =* - current && default
    #  * - default
    

    if not, try running rvm use 1.9.3 --default

  3. When trying to run your script as root, be sure to use rvmsudo ./yourscript.rb instead of sudo ./yourscript.rb, this makes sure it sets the correct $PATH.

Let me know the outcome of the above three steps.

Added by: Dr. Ashton Morar

Answer: 3

34 hours ago

I added #!/home/homeuser/.rvm/bin/ruby instead of #!/usr/bin/env ruby. So I guess this means that /usr/bin/env points to the system ruby, and not any of the rvm rubies.

Problem solved, although it would be nice to be able to use #!/usr/bin/env ruby so I can move my ruby script from Desktop to Laptop without having to change #!/home/homeuser/.rvm/bin/ruby (slightly different path on my desktop due to different user name). Maybe a symbolic link?

Added by: Dr. Don Monahan

Popular Search

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9