10

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.

4 Answers4

9

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
pyrmont
  • 103
  • 4
Elliott Frisch
  • 2,998
  • 1
  • 21
  • 22
  • I'm actually receiving the same error. ENV_PATH didn't help. I've added it to both ENV_PATH for normal user and super user. Is login the correct file for headless bash? –  Apr 18 '14 at 17:32
  • 2
    @SandroDzneladze: In Ubuntu the PATH variable is set in `/etc/environment`. That's where I would change it rather than in `/etc/login.defs`. – Gunnar Hjalmarsson Apr 18 '14 at 19:19
  • 1
    @GunnarHjalmarsson looks like a better place yes. But it doesn't fix the problem. –  Apr 19 '14 at 07:29
  • I tried the solution, somehow it is not working for ruby-2.2.2 and Ubuntu 14.04.2 LTS – AMIC MING Oct 26 '15 at 17:17
1

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.

Kalle Richter
  • 5,935
  • 20
  • 69
  • 101
Va As
  • 111
  • 4
  • I tried the solution, somehow it is not working for ruby-2.2.2 and Ubuntu 14.04.2 LTS – AMIC MING Oct 26 '15 at 17:17
  • What's the error? There are some install issues on Ubuntu with Ruby 2.2.+: http://ryanbigg.com/2014/10/ubuntu-ruby-ruby-install-chruby-and-you/ I'm still using v1.9.3 -- not looking forward to upgrading. – Va As Oct 26 '15 at 23:05
1

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

  • 4
    Hello Nihanth and than you for the answer! /usr/bin/env is not a directory on Ubuntu machines. Also your link command is missing a parameter. – Matt Bruzek Nov 09 '15 at 16:57
0

I got the same error

#!/usr/bin/env ruby in top of my script leads to

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

if I execute the script.

My solution was as simple as hard to find:

The encoding of linefeeds in my script /sourcecode editor was set to "windows style (CR + LF)".

After switching it to "unix style (LF)" and saving my script again, the error is gone.

Seems the Carriage return (CR) sign was left behind the "ruby" so theres no ruby filname.script but ruby\R filename.script which leads to the error.

Zanna
  • 69,223
  • 56
  • 216
  • 327
Kai
  • 1