Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 910
waldyr.ar Avatar asked Aug 30 '12 01:08

waldyr.ar


People also ask

How do I change my gem bundler?

To use different gem versions, you could use this pattern: your-gem _version_ . For example, bundle _1. 10.6_ -v . Hope that will help.

Where are bundler gems installed?

In addition, the user deploying the application may not have permission to install gems to the system, or the web server may not have permission to read them. As a result, bundle install --deployment installs gems to the vendor/bundle directory in the application. This may be overridden using the --path option.


1 Answers

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 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:

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 
like image 177
werkshy Avatar answered Sep 21 '22 20:09

werkshy