开发者

New installation of Ruby Enterprise Edition - "gem" recognised but "sudo gem" isn't

I've just installed Ruby Enterprise Edition on a fresh Ubuntu 10.04 server. I went to install my first gem, and hit a weird problem I never saw before.

Without sudoing, if I just type 'gem' I get the blurb about gem. I can switch to root and do gem install gemname or give the full path to the gem exe, but if I do sudo gem install gemname I get an odd error sudo: gem: command not found.

If I do gem install gemname without sudo, it tells me I don't have permission to alter the gem folder (which is fair enough). It looks like something funny's开发者_C百科 happening when I sudo, basically.

I've added the Ruby bin path to my PATH variable in my .bashrc file, like so:

export PATH=/opt/ruby-enterprise-1.8.7-2011.01/bin:$PATH

then reloaded .bashrc with source. Any ideas, anyone?


try sudo -s and then gem install gemname.

Long Answer .bashrc file only affects the bash shell you are in, and sudo does not know about it because sudo does not directly look at your .bashrc. You can use sudo -s to get around this. You can also use sudo -E to try to preserve the environment while running sudo commands.

Using /etc/profile to change your PATH instead of .bashrc can also work as well.


Try this:

gem install sqlite3-ruby


If you're using RVM, use rvmsudo gem install gemname.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜