Memo #4: Managing Ruby Gems

Posted by Dmytro Shteflyuk on under Ruby & Rails

RubyGems The power of Ruby is not only in its flexibility. It allows to create easy to maintain reusable parts of software, and also provides a way to redistribute them and integrate with your applications — RubyGems system. The only thing that could hurt developer’s brain is managing installed gems. When you are updating already installed gem, previous version will stay in gems folder and will be available to use. But why do you need all these obsolete libraries? There is a command to cleanup stale libraries in RubyGems — gem cleanup.

First thing I want to mention is gems documentation. Every gem in system has powerful documentation based on rdoc, built during an installation procedure. The easiest way to view these docs is to run gem server and open http://localhost:8808/ in browser:

1
gem server

You will be able to review which gems has been installed, and check their documentation.

I’m pretty sure you have lots of gems with the same name, but different versions. You could use the following command to remove all gem versions except the latest one:

1
gem cleanup

That’s all. You have only latest gems installed. But wait, what about Max OS X users, who have pre-installed Ruby? They (actually we) are in trouble, because…

Fixing problem with gem cleanup on Mac OS X 10.5.x (Leopard)

On Mac OS X when you will try to use this command, you will hit following error:

1
2
Attempting to uninstall sqlite3-ruby-1.2.1
ERROR:  While executing gem ... (Gem::InstallError)

That’s common problem and I will show how to fix it. First, run following command:

1
2
3
4
5
6
7
8
9
10
11
12
kpumuk@kpumuk-mbp~: gem list -d sqlite3

*** LOCAL GEMS ***

sqlite3-ruby (1.2.4, 1.2.1)
    Author: Jamis Buck
    Homepage: http://sqlite-ruby.rubyforge.org/sqlite3
    Installed at (1.2.4): /Library/Ruby/Gems/1.8
                 (1.2.1): /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8

    SQLite3/Ruby is a module to allow Ruby scripts to interface with a
    SQLite3 database.

You may now uninstall the offending gem with:

1
gem uninstall --install-dir  /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8 sqlite3-ruby

So, in general

1
gem list -d <gem-name>

will get you the location of the gem, and

1
gem uninstall --install-dir </install/directory> <gem-name>

will uninstall the gem (found here.)

3 Responses to this entry

Subscribe to comments with RSS

Belching Blech
said on April 17th, 2009 at 04:08 · Permalink

OK so I did that and it got rid of the old sqlite3 gem, which is nice. So now after that’s over do you want me to run ‘gem cleanup’? Because when I do it says ‘Cleaning up installed gems…Attempting to uninstall mongrel-1.1.4…ERROR: While executing gem…(Gem::InstallError)…Unknown gem mongrel=1.1.4’. So what should I do about that error? I’ve tried sudo, to no avail.

said on April 17th, 2009 at 09:06 · Permalink

You should exactly what you did to remove sqlite3!

1
~$ gem list -d mongrel

will show you where the mongrel gem is placed.

1
gem uninstall --install-dir  /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8 mongrel

There will be several gems which need such procedure to uninstall.

Belching Blech
said on April 17th, 2009 at 21:36 · Permalink

Well I did that and now when I run my rails apps they don’t work. I get “Status: 500 Internal Server Error no such file to load — sqlite3” Hmm.

Comments are closed

Comments for this entry are closed for a while. If you have anything to say – use a contact form. Thank you for your patience.