I\'m trying to install rubyrep on CentOS, and when executing sudo gem install rubyrep
I get the error sudo: gem: command not found
. Sudo and gem a
From http://web.archive.org/web/20130405074724/http://www.kleinfelter.com/node/188:
There are hundreds of reports on the net about "sudo: gem: command not found". Out of the dozen or so I looked at, the suggested resolution amounted to "ensure that 'gem' is in your PATH."
Yep. It is in my path. That is to say, the following works:
gem --help
but the following fails:
sudo gem --help
Further confusing matters, gem is in the path shown by:
sudo echo $PATH
The trick is that sudo doesn't use $PATH for its path on some editions of Linux. This behavior is considered "more secure." (See sudo changes PATH - why? ).
Bah! It is still a pain to work around. You have to get 'gem' into the path (not simply the $PATH!) You'll read about options you can pass to sudo, and that is fine and dandy when you type the command-line yourself. When someone's script invokes sudo for you, you're stuck with the command line that it uses.
I fixed it by doing:
alias sudo='sudo env PATH=$PATH'
as suggested in sudo changes PATH - why?.
Try without sudo
. You should only use sudo
if you did a root installation of ruby, which is not recommended.
If anyone runs across this, like I did, and the without sudo isn't an option. You may want to check your sudoers for the 'secure_path'.
If this doesn't include the path of your installation/gem/ruby (which gem). Then you'll also get this error.
Fedora 23, built from source.
sudo env PATH=$PATH gem install rails
It works for me.