I did a bundle show
and get the complete path to a gem directory.
Unfortunately, I removed the directory using rm -r gem_path
. Then my rails app isn't working anymore. If I try start server or start rails console it outputs the following error:
<class:Application>
: uninitialized constantMyAPP::Application::Gem
(NameError)
What should I do to have it back?
I tried bundle install
or bundle update
in hope of forcing the bundle to search the gem and install it back, but didn't work.
I also tried delete the Gemfile.lock
and run bundle install
. Nothing changed, same error.
The gem in question is Act as taggable on.
First I did a
gem q --L
, the shortcut forgem query --local
. It outputs me the all the local gems installed.And then, following DVG advice, I uninstalled the gem using its correct name
gem uninstall acts-as-taggable-on
and ranbundle install
. After that I was able torails c
orrails s
again without any problem.If using rbenv, this will let you completely uninstall and re-install a gem such as rmagick:
First: Try a simple uninstall/reinstall
If that doesn't work, you can remove all trace of the installed gem. Find your gem installation location:
Your gem installation prefix will either be the default e.g.
~/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0
or something you set e.g..vendor
Clear out the gem directory:
Clear out the compiled gem cache:
Also clear out bundler's spec cache:
Then you can re-install:
If you're trying to reinstall rake,
gem pristine rake
will fail withSkipped rake-10.X.X, it is a default gem
and bundle won't install it either, because it can't uninstall it.If you're using rvm, it seems the easiest was is simply to do a
rvm reinstall 2.x.x
. At least for me,rvm repair all
also didn't help.The same probably goes for all other default gems. I'll just list them here so that the desperate googlers find some help:
If using RVM with gems in
~/.rvm/
, this works ifbundle
is not re-installing a gem.First, delete the gem source:
Clear out the compiled gem cache:
Also clear out bundler's spec cache:
Then you can re-install:
You can always use:
gem pristine acts-as-taggable-on
pristine - Restores installed gems to pristine condition from files located in the gem cache
If you just want to restore the gem for the current project you should run:
bundle exec gem pristine acts-as-taggable-on
If you've installed into
./bundle/vendor
or similar, you need to remove the gem first but explicitly specify the GEM_HOME, e.g.This is by far the simplest way to uninstall gems installed using bundler into a vendor directory. Ideally, there would be a command
bundle uninstall
orbundle reinstall
, etc.If your goal is to simply reinstall, the following command will help:
If you're like me and have several web-applications under a directory (e.g.
/srv/http
), the following does it in all directories: