Bundler Puts My Gems in My Project Directory

Bundler puts my gems in my project directory

You are probably running the following command: bundle install bandsintown. That command tells bundler to install gems into the bandsintown subdirectory of your application. In order to install gems, all you need to do is modify your Gemfile and run bundle install.

Bundler will remember the location that you last specified in the .bundle/config file. So, in order to "reset" bundler's memory. In your application's directory, run rm -r .bundle/config.

Then, after updating your Gemfile, simply run bundle install

Why are gems installed in my project directory?

Bundler was remembering the location from the first time I ran bundle install. Had to 'reset' bundler's memory be running rm -r .bundle/config

Why Bundle Install is installing gems in vendor/bundle?

  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

How do I get Bundler to consider local gems as already installed ?

This trick is done using bundler.

Let's say that gem foo depends upon gem bar. Then in foo's Gemfile, use bundler's path option to point to gem bar:

gem "bar", path: "/home/wayne/lab/bar"

then bundle install

After that, commands such as bundle exec rspec, bundle exec rake features, etc., will use the gem "bar" out of your local folder.

When done, revert the gem "bar" line in Gemfile to its normal form.


If you want to keep the Gemfile modification permanently, you have several options. One is to just check it in with the modification. According to the Gemfile source priority, Bundler will first try to load the gem from the local path, then fall back to installing it from the global source.

If the gem is public, your local modification might be confusing to someone who clones your gem. In that case, since a Gemfile is just ruby code, you can use, for example, an environment variable to turn on your location modification:

# When making concurrent modifications to gem "bar",
# use that gem by its local directory.
if ENV['BAR_GEM_PATH']
gem "bar", path: ENV['BAR_GEM_PATH']
end

Specify gem installation directory

You can add the following to your config.ru file:

ENV['GEM_HOME']="#{ENV['HOME']}/projects/shared/gems/ruby/1.8/gems"
ENV['GEM_PATH']="#{ENV['GEM_HOME']}:/var/lib/ruby/gems/1.8"
require 'rubygems'
Gem.clear_paths

This will tell your rack app where to look for gems.

Also configure your server .bashrc:

export GEM_HOME="$HOME/projects/shared/gems/ruby/1.8/gems"
export GEM_PATH="$GEM_HOME:/var/lib/ruby/gems/1.8"

Where does bundler store gems?

It depends. In the usual development setup they are installed where they would be when you install a gem "normally" (by running gem install foo) and bundler won't reinstall gems that are already there. This location depends on how rubygems itself is configured.

If you run bundle install with the --deployment option then the gems will be installed in a location unique to your app (you can pass this as a separate option but it defaults to vendor/bundle)

You can also run bundle package to store all the .gem files your app uses in vendor/cache. Running bundle install will prefer gems in vendor/cache to gems in other locations.

gem from rubygems installs in gems folder, but same gem from github installs in bundler/gems

You're using bundler and a Gemfile in your app but not invoking your app with bundler, so when you call require 'colorize' it doesn't work because only bundler can tell the app where to find the gem.

Your simplest solution is to invoke your app with bundler:

bundle exec ruby color.rb

Installing Gems with Bundler == Big problem

That is because you also have to address where the gem location ( specifically where bundler is installed ) in your nginx start script as well.

bin/start

#!/bin/bash

TMPDIR=/home/shadyfront/webapps/truejersey/tmp GEM_HOME=/home/shadyfront/.rvm/gems/ruby-1.8.7-p330@true /home/shadyfront/webapps/truejersey/nginx/sbin/nginx -p /home/shadyfront/webapps/truejersey/nginx/


Related Topics



Leave a reply



Submit