Uninstalling a Gem

Table of contents:


You want to remove an installed gem from your Ruby installation.


From the command line, use the gem uninstall command:

	$ gem uninstall blinkenlights
	Attempting to uninstall gem linkenlights
	Successfully uninstalled blinkenlights version 0.0.2

From Ruby code, the most reliable way to uninstall a gem is to simulate a command-line invocation with the Gem::GemRunner class. This code installs a gem, then immediately removes it:


	Gem::GemRunner.new.run([uninstall, linkenlights])
	# Successfully uninstalled blinkenlights version 0.0.4

Uninstalling a gem can disrupt the normal workings of your Ruby programs, so I recommend you only uninstall gems from the command line. That way, theres less chance of a bug wiping out all your gems.


Since rubygems can manage multiple installed versions of the same gem, you won usually have to remove old copies of gems. There are three main reasons to remove gems:

  1. You find out that a particular version of a gem is buggy, and you want to make sure it never gets used.

  2. You want to save disk space.

  3. You want to clean up the list of installed gems so that its more obvious which gems you actually use.

If uninstalling a gem would leave another installed gem with an unmet dependency, youll be told about the dependency and asked whether you want to go through with the uninstall anyway. Youll get this interactive prompt whether you run the gem uninstall command or whether you use the Gem::Uninstaller class from Ruby code.

	Gem::Uninstaller.new(actionpack, {}).uninstall
	# You have requested to uninstall the gem:
	# actionpack-1.8.1
	# actionmailer-0.9.1 depends on [actionpack (= 1.8.1)]
	# If you remove this gem, the dependency will not be met.
	# Uninstall anyway? [yN]

The sources gem is a special gem that tells rubygems to look for remotely installable gems at http://gems.rubyforge.org/ by default. If you uninstall this gem, you won be able to install any more gems, except through complicated hacks of the classes in the Gem module. Just don do it. Not even if you never plan to install any gems from rubyforge.org. Not even if youd never thought of doing it until I brought it up in this recipe, and now you e curious.

You did it, didn you? Now youll have to reinstall rubygems by rerunning its setup.rb script.



Date and Time



Files and Directories

Code Blocks and Iteration

Objects and Classes8

Modules and Namespaces

Reflection and Metaprogramming


Graphics and Other File Formats

Databases and Persistence

Internet Services

Web Development Ruby on Rails

Web Services and Distributed Programming

Testing, Debugging, Optimizing, and Documenting

Packaging and Distributing Software

Automating Tasks with Rake

Multitasking and Multithreading

User Interface

Extending Ruby with Other Languages

System Administration

Ruby Cookbook
Ruby Cookbook (Cookbooks (OReilly))
ISBN: 0596523696
EAN: 2147483647
Year: N/A
Pages: 399

Similar book on Amazon

Flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net