53

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.)

6 Answers 6

113

You can use

gem uninstall <gem-name>

2
  • 13
    Why are there so many upvotes on this one? The question is how to remove it from RoR application. And for that you just need to remove it from Gemfile.rb and bundle again. That's all. And for removing dependencies you have to delete associated files and dependencies.
    – Sachin
    Sep 29, 2017 at 6:26
  • And for new Rails applications, we can have the help of irb to save your system and work on somewhat virtual ruby version based environments.
    – Sachin
    Sep 29, 2017 at 6:28
48

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.

3
  • Will this also remove the files the gem created?
    – Oded Harth
    Mar 9, 2011 at 18:29
  • It typically doesn't add any files unless you explicitly specify, but it may modify some of the existing files, like routes.rb. If you want to roll back those modifications, you can revert through the source control as @harald said. Mar 9, 2011 at 18:33
  • Will this remove all the generators too? Aug 10, 2014 at 3:09
19

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.

6

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

0
1

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)

-3

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.

3
  • I am using git. Is there a way to restore my application with git?
    – Oded Harth
    Mar 9, 2011 at 18:38
  • Yep, look up 'git revert' or 'git reset' depending on your situation, one of those should probably help you.
    – harald
    Mar 9, 2011 at 21:09
  • 2
    This is clearly not the right answer. Using git or more generally VCS to remove installed gem or library is really crappy. Better use gem-uninstall <gem name> as suggested @rtfminc, or just remove the dependancy from the Gemfile and run bundle install in your app as @srdjan-pejic suggested.
    – Habovh
    Oct 12, 2015 at 11:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.