How to reinstall a gem using bundler

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 constant MyAPP::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 .


If using rbenv, this will let you completely uninstall and re-install a gem such as rmagick:

First: Try a simple uninstall/reinstall

gem uninstall rmagick
bundle install

If that doesn't work, you can remove all trace of the installed gem. Find your gem installation location:

bundle show rmagick
BUNDLE_DIR=$(dirname $(dirname $(bundle show rmagick)))
echo $BUNDLE_DIR

Your gem installation prefix will either be the default eg ~/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0 or something you set eg .vendor

Clear out the gem directory:

rm -rf $BUNDLE_DIR/gems/rmagick-*

Clear out the compiled gem cache:

rm $BUNDLE_DIR/cache/rmagick*.gem

Also clear out bundler's spec cache:

rm $BUNDLE_DIR/specifications/rmagick*gemspec

Then you can re-install:

bundle 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


First I did a gem q --L , the shortcut for gem query --local . It outputs me the all the local gems installed.

actionmailer (3.2.8, 3.2.6, 3.2.1, 3.1.0)
actionpack (3.2.8, 3.2.6, 3.2.1, 3.1.0)
activemodel (3.2.8, 3.2.6, 3.2.1, 3.1.0)
activerecord (3.2.8, 3.2.6, 3.2.1, 3.1.0)
activeresource (3.2.8, 3.2.6, 3.2.1, 3.1.0)
activesupport (3.2.8, 3.2.6, 3.2.1, 3.1.0)
acts-as-taggable-on (2.3.3)
...

And then, following DVG advice, I uninstalled the gem using its correct name gem uninstall acts-as-taggable-on and ran bundle install . After that I was able to rails c or rails s again without any problem.

链接地址: http://www.djcxy.com/p/6106.html

上一篇: 耙子迁移中止

下一篇: 如何使用捆绑器重新安装宝石