sudo: ruby: command not found after ssh
The error you are getting indicates that ruby
is not in the sudo $PATH
. TO get around this, you either need to export your environment correctly:
sudo -E ruby
Or, just use the full path. Run type ruby
as your regular user, and use that with sudo
. For example:
$ type ruby
ruby is /usr/bin/ruby
$ sudo /usr/bin/ruby
Related videos on Youtube
Bijendra
Experienced engineer with background of working in web and communication industry. Startup and OpenSource enthusiast, mentor for RoR groups. Have worked with multiple backend technologies. Programming : Ruby, Python, Ruby on Rails, FLASK Databases : MYSQL, Postgres, Elastic-search, MongoDB, Solr Web: HTML, JS, SCSS, AJAX, JQuery, Angular DevOps: Docker, Bash, Nginx, Apache, HaProxy, Perforce, AWS, Git
Updated on September 18, 2022Comments
-
Bijendra over 1 year
I'm working with ec2 instances and was trying to execute a ruby script on another instance after ssh to that instance. I have a ruby script which updates configuration files, so i need to run that script as super user. when i run the script manually on that instance,
sudo ruby recreate-532d01c.rb
, the error that comes issudo: ruby: command not found
Running simple scripts with no root permissions works, eg.
ruby file_1.rb
.Using rvmsudo in place of sudo executes the script with warning,
ubuntu@ip-10-0-0-111:~$ rvmsudo ruby recreate-82bb000012.rb Warning: can not check `/etc/sudoers` for `secure_path`, falling back to call via `/usr/bin/env`, this breaks rules from `/etc/sudoers`. Run: export rvmsudo_secure_path=1 to avoid the warning, put it in shell initialization file to make it persistent. In case there is no `secure_path` in `/etc/sudoers`. Run: export rvmsudo_secure_path=0 to avoid the warning, put it in shell initialization file to make it persistent.
I tried to execute the below command from rails console of one of the instance to test and it fails to recognize ruby as command
1.9.3-p545 :002 > system("ssh -i /home/ubuntu/.ssh/own_key.pem ubuntu@**.***.***.** ruby execute-52d.rb") bash: ruby: command not found
I tried with possible solutions over web, but could not resolve the issue. I have the same configuration running for one of my old aws acount, this is a newly created account. Not sure if this could be issue in any way as currently ec2 instances fall under vpc by default and have some changes after dec 2013
-
terdon about 10 yearsSounds like a simple PATH issue. Just run
type ruby
and then with sudo use the full path to theruby
executable. -
Bijendra about 10 yearsi will check with this. thanx
-
Bijendra about 10 years@terdon i have installed rvm as a single user in the instance in which i have scripts to run after ssh. Do i need to install multi user rvm or it will work
-
terdon about 10 yearsI don't know, I don't use
ruby
but the error you get is not ruby-specific. It is simply because the ruby executable in not in root's path. Does it work if you use the whole path as I suggested? -
Bijendra about 10 yearsThanx it worked
-