2

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

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Max Williams
  • 32,435
  • 31
  • 130
  • 197

3 Answers3

0

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.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Ken Li
  • 2,578
  • 4
  • 25
  • 26
  • thanks tin man. I tried changing /etc/profile but that didn't help. Do i need to reload it? I tried exiting and ssh'ing on again but no dice. Changing to root *does* work like i said but i still want to be able to straight sudo it. – Max Williams Feb 15 '11 at 09:19
0

Try this:

gem install sqlite3-ruby
Keating
  • 3,380
  • 10
  • 34
  • 42
  • Keating - this seems like the answer to a different question, i never said anything about sqlite. – Max Williams Jun 16 '11 at 08:38
  • I got an error when I install sqlite3-ruby with command: sudo gem install sqlite3-ruby. So I search the error, then found your title. When I finished it with command : gem install sqlite3-ruby. I just suggest you try it. – Keating Jun 30 '11 at 13:23
0

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

Calvin
  • 8,697
  • 7
  • 43
  • 51