76

Whenever I do bundle install all of the gems get installed at

app_dir/vendor/bundle

path and consumes loads of disk space. I also tried installing gems where it should get installed i.e gemsets while development by this:

bundle install --no-deployement

but this isn't working for me and installeing gems at vendor/bundle. How can I make it to be installed globally for all applications or in ruby gemsets location ? I also tried removing .bundle/config but nothing changed.

I am using:

rvm version: 1.23.14
ruby version: 2.0.0-p247
rails 3.2.13

Here is my ~/.bash_profile:

export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
eval "$(rbenv init -)"
alias pg='pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log'

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function

My ~/.bashrc:

PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting

Some other information that you might need:

aman@Amandeeps-MacBook-Pro ~/Projects/qe (develop)*$ which bundle
/Users/aman/.rvm/gems/ruby-2.0.0-p247@global/bin/bundle

aman@Amandeeps-MacBook-Pro ~/Projects/qe (develop)*$ rbenv which bundle
/Users/aman/.rbenv/versions/2.0.0-p247/bin/bundle

amandeep@Amandeeps-MacBook-Pro ~/Projects/qe (develop)*$ rbenv which ruby
/Users/aman/.rbenv/versions/2.0.0-p247/bin/ruby

aman@Amandeeps-MacBook-Pro ~/Projects/qe (develop)*$ rbenv gemset active
rbenv: NO such command `gemset'

aman@Amandeeps-MacBook-Pro ~/Projects/qe (develop)*$ which rails
/Users/aman/.rvm/gems/ruby-2.0.0-p247@global/bin/rails

I tried this also but didn't helped:

bundle install --system

and removing .bundle directory.

Please help me in installing gems in gemsets not vendor/bundle or a default place.

Gaurav Sharma
  • 477
  • 9
  • 24
Amandeep Singh Bhamra
  • 1,133
  • 1
  • 8
  • 15

7 Answers7

121

In your project folder you will have .bundle directory that holds configuration for bundler. try deleting that folder. it should reset the install path for your gems back to system-wide settings.

In the case you just want to edit the install path, opening .bundle/config with your favorite editor should show you the path to vendor/bundle. Removing that line will restore it to defaults without removing other configs you might have.

Also, another less frequent scenario is your system-wide settings being messed up. According to @NaoiseGolden:

I had to delete .bundle from my Home folder (rm -rf ~/.bundle). You can check out your configuration running bundle env

Mic Fok
  • 837
  • 11
  • 12
Iuri G.
  • 10,460
  • 4
  • 22
  • 39
  • 1
    Likewise solved it for me, but can anyone explain how those settings got set in the first place? They're not in my source control and I sure didn't create them. – Matt Jun 23 '14 at 17:15
  • 6
    @Matt At some point you ran bundle with `--deployment` flag or `--path` flag. That resulted changing install path to `vendor` and the settings got autosaved to `.bundle`. That's the most probable scenario. – Iuri G. Jun 23 '14 at 17:23
  • 9
    I had to delete .bundle from my Home folder (`rm -rf ~/.bundle`). You can check out your configuration running `bundle env`. – Naoise Golden Feb 07 '15 at 11:40
  • 4
    @IuriG. is absolutely right. I looked back through my bash command history and found that, for some reason or another (probably following advice on some blog post or SO question without knowing what I was doing), I had run `bundle --path=vendor/bundle`, which resulted in the creation of `.bundle/config`. This solution (`rm -rf .bundle`) was very simple and fixed everything. – sixty4bit May 28 '15 at 14:09
  • 1
    @OP original post: This worked perfectly, thank you. Saved me so much time. – kush Jan 12 '22 at 22:46
34

Try installing using

bundle install --system

I think initially the bundle install was run with --path flag and bundler now rememebers that confguration.

From the bundler man page

Some options are remembered between calls to bundle install, and by the Bundler runtime.

Subsequent calls to bundle install will install gems to the directory originally passed to --path. The Bundler runtime will look for gems in that location. You can revert this option by running bundle install --system.

EDIT: As mentioned in comments below, and also otherwise, this installs the gems system wide. In case you are using rvm etc to manage your environment for different apps, check @IuriG's answer mentioned above.

Community
  • 1
  • 1
Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
14
  1. Use bundle env to view paths and bundle configuration

  2. After this set bundle path to ~/.rvm/gems/ruby-2.0.0-p247 like this:

    bundle install --path ~/.rvm/gems/ruby-2.0.0-p247
    

    which is global and also you can use your own custom path.

  3. Post this bundle install will never need path again and will always install all of your gems in that directory(~/.rvm/gems/ruby-2.0.0-p247 in my case) for that app not in app_folder/vendor/bundle

Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
Amandeep Singh Bhamra
  • 1,133
  • 1
  • 8
  • 15
7

Try running bundle env. This will tell you where the path configuration is set.

Tim Moore
  • 8,958
  • 2
  • 23
  • 34
  • This helped in viewing the path. Now I have changed bundle path to ~/.rvm/gems/ruby-2.0.0-p247 and made it not to install at vendor/bundle – Amandeep Singh Bhamra Nov 15 '13 at 05:43
  • If you're trying to install to your system gem location, I recommend _not_ setting it inside bundle config at all. You can just delete the line. Bundler will default to using your `GEM_HOME`. – Tim Moore Dec 08 '14 at 02:46
3

First of all, acording to your info, it seems that you have installed both rvm and rbenv. Thats a very bad idea. You have to delete one of them (rbenv + bundler works like a charm for me, didnt try rvm).

In regard to your question check .bundle/config in your project, as all the configuration for bundle to that project lies there (if its still deleted, you can create a new one). You migh want to add this line (or change it, if its already there): BUNDLE_DISABLE_SHARED_GEMS: '0' for sharing gems, they go where your BUNDLE_PATH: is set (BUNDLE_PATH: vendor in my case).

For the global configuration file look in ~/.bundle/config

Also this man page could be of use: bundle config

kiddorails
  • 12,961
  • 2
  • 32
  • 41
Rav.-
  • 39
  • 2
1

To Install Gem in system wide avoiding path vendor/bundle, just run the following command in project directory

bundle install --system
Rokibul Hasan
  • 4,078
  • 2
  • 19
  • 30
0
$ brew install rbenv
$ rbenv install 2.7.6
$ rbenv install -l
2.7.6
$ rbenv global 2.7.6
$ gem install bundler
$ brew install rbenv-gemset
$ rbenv gemset create 2.7.6 mygemset
$ gem env home
/Users/myuser/.rbenv/versions/2.7.6/gemsets/mygemset
$ gem install rails
$ rails new myapp && cd myapp
$ bundle install
$ bundle show --paths
/Users/myuser/.rbenv/versions/2.7.6/gemsets/myapp/gems/actioncable-7.0.1
...
$ bundle config set --local path 'vendor/bundle'
$ file .bundle
$ .bundle: directory
$ cat .bundle/config
---
BUNDLE_PATH: "vendor/bundle"
$ bundle install # Note from time to time you will get some bizarre error "Could not find timeout-0.2.0 in any of the sources". Simply delete Gemfile.lock and run bundle install again.
$ bundle show --paths
/Users/myuser/myapp/vendor/bundle/ruby/2.7.0/gems/actioncable-7.0.4
$ bundle config set --local system 'true' # or you may want to   delete BUNDLE_PATH: "vendor/bundle" from .bundle/config
$ rm -rf vendor/bundle
$ rbenv gemset active
mygemset global
$ bundle install
$ bundle show --paths
/Users/myuser/.rbenv/versions/2.7.6/gemsets/mygemset

All in all, when you install a ruby version manager, such as the preferable rbenv, then it will install gems according to its setup. However, if you update .config/bundle in your project to use 'vendor/bundle', then that's where 'bundle install' will install gems. Sometimes this is used to keep project specific gems, instead of using a gemset tool like rbenv-gemset. Other times it is required for deployment, such as deploying to AWS Lambda on its ruby2.7 runtime. The use of 'vendor/bundle' can be easily removed by removing its reference from .config/bundle as shown above. Once it is removed, it will default to the gem environment that exists globally, which in the above case is managed by rbenv.

Daniel Viglione
  • 8,014
  • 9
  • 67
  • 101