Bundler 把宝石放在哪里?

我知道在使用 gem install时,gem 将存储在/home/username/. rvm/gems/下面,gem 将安装在该下面。

但是如果我使用 Bundler 并在 Gemfile 中指定 gem,当我运行 bundle install 时,这些 gem 将存储在哪里?如果我已经使用 gem install安装了 gem,如果我运行 bundle install,它会使用之前使用 gem install安装的 gem 吗?

51195 次浏览

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.

Here /usr/local/lib/ruby/gems/2.1.0/gems/ and here: /usr/local/lib/ruby/gems/2.1.0/bundler/gems/.

If you want to find out where a particular gem is stored you can run bundle info <gem-name>. For example:

user@host$ bundle info rake
/var/bundle/ruby/2.1.0/gems/rake-10.4.2

For older versions of rake, the command could be bundle show <gem_name>.

Note that gems are also installed into the bundle folder within your "Gem Path" (see: bundle env). This happens, for example, with gems installed from git:

gem 'my-gem', git: "https://github.com/x/y.git"

I assume this is so that custom installations don't conflict with installations from a gem server.

I use bundle config path to see where gems are stored.