How to remove gem from Ruby on Rails application?

Ruby on-RailsRubyRubygems

Ruby on-Rails Problem Overview


I have installed a gem on my Rails application (devise). After I installed the gem, I realized that I don't need it.

I want to remove the gem, its dependencies and the files it created on my application. In other words, I want to restore the system to what it used to be before the gem. How can I do this? (I'm using Ruby on Rails 3.)

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

You can use

gem uninstall <gem-name>

Solution 2 - Ruby on-Rails

If you're using Rails 3+, remove the gem from the Gemfile and run bundle install.

If you're using Rails 2, hopefully you've put the declaration in config/environment.rb. If so, removing it from there and running rake gems:install should do the trick.

Solution 3 - Ruby on-Rails

Devise uses some generators to generate views and stuff it needs into your application. If you have run this generator, you can easily undo it with

rails destroy <name_of_generator>

The uninstallation of the gem works as described in the other posts.

Solution 4 - Ruby on-Rails

For Rails 4 - remove the gem name from Gemfile and then run bundle install in your terminal. Also restart the server afterwards.

Solution 5 - Ruby on-Rails

How about something like:

gem dependency devise --pipe | cut -d \  -f 1 | xargs gem uninstall -a

(this assumes that you're not using bundler - but I guess you're not since removing from your bundle gemspec would solve the problem)

Solution 6 - Ruby on-Rails

You are using some sort of revision control, right? Then it should be quite simple to restore to the commit before you added the gem, or revert the one where you added it if you have several revisions after that you wish to keep.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionOded HarthView Question on Stackoverflow
Solution 1 - Ruby on-RailsrtfmincView Answer on Stackoverflow
Solution 2 - Ruby on-RailsSrdjan PejicView Answer on Stackoverflow
Solution 3 - Ruby on-Railsd135-1r43View Answer on Stackoverflow
Solution 4 - Ruby on-RailsGagan GamiView Answer on Stackoverflow
Solution 5 - Ruby on-RailscybertoastView Answer on Stackoverflow
Solution 6 - Ruby on-RailsharaldView Answer on Stackoverflow