5

I have a machine that is running Ubuntu Hardy, which provides its own RubyGems package. Unfortunately that version of RubyGems (1.1.1) is too old to do anything useful with, so I decided to manually update RubyGems to the current version (1.3.6). That part went smoothly, and if I do gem -v, I get 1.3.6 which is expected. The problem is when I try to do: sudo gem install rack, it returns this error:

ERROR:  While executing gem ... (Errno::EACCES)
Permission denied - /home/username/.gem

Usually when I install gems as root, it knows to install it into /usr/lib/ruby/gems, so why is it checking my home directory at all? Another quirk is when I do gem install rack (not as root), it says:

ERROR:  While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /usr/lib/ruby/gems/1.8 directory.

which is where I want it to go. I've already tried clearing source_caches, trying different versions of RubyGems (1.3.5), forcing installation into /usr/lib with -i to no avail. Any ideas on why RubyGems is so insistent on checking my /home directory when installing as root?

Kenny Peng
  • 1,891
  • 4
  • 18
  • 26

4 Answers4

2

Sounds like it could be a path issue coupled with having multiple versions installed.

Any difference in output between:

sudo gem env

and

gem env
  • No difference in the two, though in the GEM PATHS section: `/usr/lib/ruby/gems/1.8` and `/home/username/.gem/ruby/1.8`. Shouldn't that not be there by default with sudo? – Kenny Peng Apr 22 '10 at 22:12
  • They're the same on my system, but only after I went through and 'scrubbed' everything after recompiling 1.9. Things I checked: 1. Deleted the un-used gem command (had one in /usr/bin and /usr/local/bin 2. Checked my ~/.gemrc file and cleaned the path up to point to my gem path in /usr/local/lib. Used my ~/.gem folder as a backup 3. Matched my GEM_HOME and GEM_PATH environment variables up (in .profile/.bash_profile/.bashrc) with the .gemrc file 4. Checked permissions on the gem folders 5. You might also check to see if you have anything in /etc/gemrc – SundayEdition Apr 23 '10 at 04:12
  • So I went through these suggestions and they all seem to check out: 1) only one gem executable in /usr/bin, 2) no .gemrc, 3) I never set these variables in my .profile, 4) gem folders had permissions for root, which sudo should be fine with, 5) no /etc/gemrc. The only other hitch is maybe the fact that my home directory lives on AFS screws things up? – Kenny Peng Apr 23 '10 at 15:52
  • Check this: http://stackoverflow.com/questions/257616/sudo-changes-path-why Maybe the old version of gem wasn't installed in /usr/bin or /usr/local/bin, and sudo is picking up a different PATH variable (to gem) or a GEM_PATH (which points to your /home/username path) from somewhere? You might check /etc/environment as well and try to find out where sudo is picking up its environment variables from (maybe a root .profile?). – SundayEdition Apr 24 '10 at 03:58
  • 3
    I believe the problem was caused by having my home directory on AFS. RubyGems seems to write metadata into your `.gem` directory (`~/.gem/specs`) regardless of whether you are running as root via sudo. But running as root means that you credentials don't carry over and you can't do anything to AFS. I ended up using `sudo su` and installing things as root proper. It did install into `/usr/lib/ruby/gems` and wrote some metadata into `~/.gem/specs`. Thanks for all the help, I was able to narrow down the scope of the problem a lot. – Kenny Peng Apr 26 '10 at 17:20
  • My output for these is exactly the same. How else can I figure out, whats wrong? – Ava Aug 22 '13 at 22:40
0

Try running:

gem environment

and checking the values for the GEM PATH. More info at http://docs.rubygems.org/read/chapter/10#page31

nutcracker
  • 2,944
  • 2
  • 17
  • 16
0

I was running into the same problem myself on Fedora 15, so I ran 'gem install' with the '--backtrace' option to see what was going on.

It turned out it was failing at /usr/lib/ruby/site_ruby/1.8/rubygems/doc_manager.rb:203 where it tried to chdir to the directory it had previously stored (the home directory of the user I was running sudo as)

I didn't extensively debug to see what the underlying cause was, just rather used a quick workaround so I could continue moving forward. The workaround was simply to cd to the root directory, eg cd /, before running the gem install command.

Hope this helps / solves your issue.

Mo Morsi
  • 111
  • 1
  • 3
-3

Woulda been easier to su (password) then chmod 755 /usr/lib/ruby/gems/1.8

Chris
  • 1
  • 1
    It's safer to install gems in your homedir or /usr/local/.... Don't mess with system installed files and don't make library folders writable to every user. It will backfire. – Munhitsu Apr 30 '12 at 21:00