Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I fix an accidental 'sudo bundle install dir_name'?

Tags:

ruby

bundler

gem

I accidentally ran sudo bundle install smtp_mail and now all my gems are in this directory called smtp_mail inside my Rails app.

I'm not sure about the default location of gems? And, my Rails app is complaining when it starts. Is there a way I can revert back?

like image 775
Jasdeep Singh Avatar asked May 02 '11 20:05

Jasdeep Singh


People also ask

How do I fix a run bundle to install missing gems?

Select Tools | Bundler | Install from the main menu. Open the Gemfile, place the caret at any highlighted gem missing in the project SDK and press Alt+Enter . Select Install missing gems using 'bundler' and press Enter .

What is bundle install?

bundle install is a command we use to install the dependencies specified in your Gemfile.


3 Answers

The path is specified in a file located in

.bundle/config  

If you delete the .bundle directory and then delete your smtp_mail directory you will be back at square one. If you really want a local (to your app) installation of the gems, I recommend you run

bundle install --path vendor/bundle

Good luck!

like image 68
Mike Farmer Avatar answered Sep 30 '22 06:09

Mike Farmer


After a bit of Googling around i was able to find the answer Just run:

sudo bundle install --system and you'll have your gems back at their appropriate system directories.

like image 23
Jasdeep Singh Avatar answered Sep 30 '22 08:09

Jasdeep Singh


pay attention on this...

from the bundle man page:

By default, bundler installs gems to the same location as gem install.

You should never use sudo bundle install. This is because several other steps in bundle install must be performed as the current user:

  • Updating your Gemfile.lock
  • Updating your vendor/cache, if necessary
  • Checking out private git repositories using your user's SSH keys

Of these three, the first two could theoretically be performed by chowning the resulting files to $SUDO_USER. The third, however, can only be performed by actually invoking the git command as the current user. Therefore, git gems are downloaded and installed into ~/.bundle rather than $GEM_HOME or $BUNDLE_PATH.

As a result, you should run bundle install as the current user, and bundler will ask for your password if it is needed to put the gems into their final location.

like image 45
ALoR Avatar answered Sep 30 '22 08:09

ALoR