coderrr

January 26, 2009

Uninstalling gems that were installed without root

Filed under: ruby — Tags: — coderrr @ 9:26 am

RubyGems 1.3.0 added the feature of allowing you to install gems without root. If you do this they will be installed into the ~/.gem directory with no extra work on your part. The trickier part is uninstalling them:

$ gem install hpricot
WARNING:  Installing to ~/.gem since /usr/lib/ruby/gems/1.8 and
	  /usr/bin aren't both writable.
Successfully installed hpricot
1 gem installed
$ gem uninstall hpricot
ERROR:  While executing gem ... (Gem::InstallError)
    Unknown gem hpricot >= 0

To uninstall you have to specify the install-dir which turns out to not be ~/.gem but ~/.gem/ruby/1.8 (or the dir of whichever ruby version you are using):

$ gem uninstall hpricot --install-dir ~/.gem/ruby/1.8
Successfully uninstalled hpricot

Hope this helps someone

7 Comments »

  1. Yeah, hopefully in the future we should have a way of moving the home gems to the actual repository without having to uninstall them and then reinstall them as root just because we ran the command without sudo..

    Comment by Toledo — January 26, 2009 @ 2:27 pm

  2. Or warn you if you’re not using sudo and ask if you really want to do this…

    Comment by Jeff Schoolcraft — January 28, 2009 @ 4:55 am

  3. It’s one of stupid things in rubygems. It shouldn’t do that. The best thing what it could do is print a message which says, that user haven’t permission to install gem to default directory but it can do that by specifying manually install dir (for example ~/.gems/). I sometimes forget to add ’sudo’ and gems are installed to my homedir which is very confusing because I have to uninstall it anyway.

    Comment by Radarek — January 30, 2009 @ 8:06 pm

  4. Probably the work-around for the time being would be to set permissions on ~/.gem so that we get an authentication message when trying to install gems.

    On Mac OS X you can make set an ACL as follows:
    chmod -R +a “group:everyone deny write” ~/.gem

    gem install ya2yaml
    ERROR: While executing gem … (Errno::EACCES)
    Permission denied – /Users/rubyuser/.gem/ruby/1.8/cache/ya2yaml-0.26.gem

    Comment by Arild Shirazi — February 14, 2009 @ 9:58 pm

  5. good idea…

    how about just: chmod -R u-w ~/.gem

    Comment by coderrr — February 15, 2009 @ 9:03 am

  6. Thank you for this. The permissions work around (comment 4) is also a good idea

    Comment by Matthew Tate — March 13, 2009 @ 7:32 pm

  7. [...] Protecting your ~/.gem directory Filed under: ruby — Tags: ruby — coderrr @ 9:20 pm If you accidentally run gem install without sudo you’ll end up with the gem installed into your ~/.gem directory instead of your system gem path. This can cause annoyances, one of which I mentioned here. [...]

    Pingback by Protecting your ~/.gem directory « coderrr — March 16, 2009 @ 9:20 pm


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.