rvm /usr/bin/env: ruby no such file error

I've installed rvm + ruby systemwide.

which ruby
/usr/local/rvm/rubies/ruby-2.1.1/bin/ruby

and:

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

Everything else works fine, putting direct path of ruby in my executables work fine.


Solution 1:

The PATH is what the env program uses to search for your executables. You can change this per-user (in the $HOME/.bashrc). In order to do that, run nano $HOME/.bashrc and go to the last line, add a new line

export PATH=$PATH:/usr/local/rvm/rubies/ruby-2.1.1/bin

To change it at a system level you sudo nano /etc/login.defs and change this line

ENV_PATH        PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

to

ENV_PATH        PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/local/rvm/rubies/ruby-2.1.1/bin

Solution 2:

I realize this is a somewhat old question, but I spent a day+ trying to nail this problem down, and I found what I think is a solid best practices type of solution -- use the rvm wrappers.

/usr/bin/env ruby gives you the capability to use the Ruby version of your choice so you don't have to edit the executable shell scripts (in /bin) with a hard coded directory path to make them work (I've seen this as a suggested fix elsewhere).

As noted in the answers above, the key is the $PATH setting in /etc/environment, but I came up with a different solution.

RVM gives us a symbolic link directory of all the installed ruby versions and aliases at /usr/local/rvm/wrappers/.

If you set your $PATH var to use the wrapper directory associated with the Ruby version you want to use e.g.

PATH="/usr/local/rvm/wrappers/ruby-1.9.3-p547:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"

You will have set the RVM environment such that /usr/bin/env ruby_command will work.

At least this resolved this problem for me. I hope this helps someone out there save some time.

Solution 3:

I recently faced this issue and took a different approach, so thought of sharing it. This happens when the ruby file is not present in the directory mentioned. So create a symbolic link to the ruby file in the directory and your error should be fixed.

cd /usr/bin/env

ln -s /usr/local/rvm/rubies/ruby-2.1.1/bin/ruby