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

Hi,

I installed ruby using rvm with root user on Linux.

Now i m trying the below command as a non root user [webadmin] with sudo privileges.

sudo /usr/local/rvm/rubies/ruby-2.2.5/bin/gem install passenger

I get the below error:

I had even reset the path for both gem as well as ruby as you can see below but dont know why does it not reference.

$ sudo gem install passenger
sudo: gem: command not found
$ echo $PATH
/usr/local/rvm/rubies/ruby-2.2.5/bin:/usr/local/rvm/gems/ruby-2.2.5/bin:/usr/local/rvm/gems/ruby-2.2.5@global/bin:/usr/local/rvm/rubies/ruby-2.2.5/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/rvm/bin:/home/serviceusers/webadmin/.local/bin:/home/serviceusers/webadmin/bin


$ ls -ltr /usr/local/rvm/rubies/ruby-2.2.5/bin/gem
-rwxrwxr-x 1 root root 546 Aug 31 07:01 /usr/local/rvm/rubies/ruby-2.2.5/bin/gem
$ ls -ltr /usr/local/rvm/rubies/ruby-2.2.5/bin/ruby
-rwxrwxr-x 1 root root 138584 Aug 31 07:00 /usr/local/rvm/rubies/ruby-2.2.5/bin/ruby

The same command works with root user.

/usr/bin/env file is not even readable using vi editor.

What should i do to resolve this error.

  1. become root
  2. type the command 'which ruby'

If it fails then you have PATH variable problem.
If it returns a value, then check each and every directory in the result. Each directory has to have at least execute for other.
Or:

chmod +x directory_name

After that try running

which ruby

as another user. Make sure the PATH is correct. For all users on the system.

Tried your suggestions but still it does not work.

Please see the output below.

[root@development temp1]# which ruby
/usr/local/rvm/rubies/ruby-2.2.5/bin/ruby

[root@development temp1]# which gem
/usr/local/rvm/rubies/ruby-2.2.5/bin/gem

[root@development temp1]# ls -ltrd /usr
drwxr-xr-x 13 root root 4096 Jul 25 23:23 /usr
[root@development temp1]# ls -ltrd /usr/local
drwxr-xr-x 22 root root 4096 Aug 31 06:36 /usr/local
[root@development temp1]# chmod -R 775 /usr/local/rvm
[root@development temp1]# exit
exit

[webadmin@development temp1]$ sudo gem install passenger
sudo: gem: command not found

[webadmin@development temp1]$ echo $PATH
/usr/local/rvm/rubies/ruby-2.2.5/bin:/usr/local/rvm/gems/ruby-2.2.5/bin:/usr/local/rvm/gems/ruby-2.2.5@global/bin:/usr/local/rvm/rubies/ruby-2.2.5/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/rvm/bin:/home/serviceusers/webadmin/.local/bin:/home/serviceusers/webadmin/bin

Not sure what am i missing !!

There has to be something wrong with permissions (ACL's) on directories or there is an unprintable character in the PATH variable. Or PATH for the two users does not match.

Also try

sudo echo $PATH | cat -v

Also note:
Your

echo $PATH 

is for another user in your example, not necessarily the one you get the one you get with sudo.

3
Sorry but no luck.

Please see the output below:

[webadmin@development temp1]$ sudo echo $PATH | cat -v
/usr/local/rvm/rubies/ruby-2.2.5/bin:/usr/local/rvm/gems/ruby-2.2.5/bin:/usr/local/rvm/gems/ruby-2.2.5@global/bin:/usr/local/rvm/rubies/ruby-2.2.5/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/rvm/bin:/home/serviceusers/webadmin/.local/bin:/home/serviceusers/webadmin/bin

Did you check ACL's?

Edit: getfacl command does this.

Is your PATH variable exported? Try

export PATH

and try again.

Andrew

1 Like

AFAIK: sudo does not allow PATH or any other variables to be inherited from the calling process. It is supposed to execute the login script(s) for that user - in this case root.

Anything else (e.g., LD_LIBRARY_PATH) would compromise security.

export PATH was missing which was the problem. This has fixed the problems. Thank you.