Error sudo: gem: command not found

后端 未结 4 1369
日久生厌
日久生厌 2021-01-11 15:08

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

相关标签:
4条回答
  • 2021-01-11 15:46

    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?.

    0 讨论(0)
  • 2021-01-11 15:47

    Try without sudo. You should only use sudo if you did a root installation of ruby, which is not recommended.

    0 讨论(0)
  • 2021-01-11 15:49

    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.

    0 讨论(0)
  • 2021-01-11 16:09

    sudo env PATH=$PATH gem install rails

    It works for me.

    0 讨论(0)
提交回复
热议问题