Today I needed to execute a ruby gem executable with sudo
. But, surprisingly, bash would tell me command not found
for the gem that ran lovely without sudo
.
Gem bin
s are installed to /var/lib/gems/1.8/bin
, which is not in sudo’s PATH
. Unfortunately, you can’t change the path, since sudo
for Ubuntu is compiled with the --with-secure-path
option.
#Solution A: symlink the gems (if you need only some few gems)
sudo
, run `ln -s /var/lib/gems/1.8/bin/gem_for_sudo /usr/local/bin/gem_for_sudo#Solution B: update the path where gem install
puts executables (if you need to execute many to all gems with sudo)
/var/lib/gems/1.8/bin/
to /usr/local/bin/
(so gem
will still be aware of them)#Solution C: overwrite sudo’s secure path anyway
I discourage to do this:
sudo visudo