Ruby-on-rails 为什么捆绑安装是在供应商/捆绑中安装 gems?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19961821/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 23:02:30  来源:igfitidea点击:

Why Bundle Install is installing gems in vendor/bundle?

ruby-on-railsrubygemrvmbundler

提问by Amandeep Singh Bhamra

Whenever I do bundle installall of the gems get installed at

每当我做bundle install所有的宝石都安装在

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:

路径并消耗大量磁盘空间。我还尝试在开发时在应该安装的地方安装 gems,即 gemsets:

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/configbut nothing changed.

但这对我不起作用并且在vendor/bundle. 我怎样才能让它为所有应用程序全局安装或安装在 ruby​​ gemsets 位置?我也尝试删除.bundle/config但没有任何改变。

I am using:

我在用:

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

Here is my ~/.bash_profile:

这是我的~/.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:

我的~/.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 .bundledirectory.

并删除.bundle目录。

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

请帮助我在 gemsetsvendor/bundle或默认位置安装 gems 。

采纳答案by Amandeep Singh Bhamra

  1. Use bundle envto view paths and bundle configuration

  2. After this set bundle path to ~/.rvm/gems/ruby-2.0.0-p247like 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 installwill never need pathagain 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

  1. 使用bundle env查看的路径和包构造

  2. 在此设置捆绑路径后, ~/.rvm/gems/ruby-2.0.0-p247如下所示:

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

    这是全局的,您也可以使用自己的自定义路径。

  3. 发布此内容bundle install将不再需要path,并且将始终在directory(~/.rvm/gems/ruby-2.0.0-p247 in my case该应用程序中安装所有宝石) 不在该应用程序中app_folder/vendor/bundle

回答by Iuri G.

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

在您的项目文件夹中,您将拥有.bundle保存bundler. 尝试删除该文件夹。它应该将您的 gem 的安装路径重置回系统范围的设置。

In the case you just want to edit the install path, opening .bundle/configwith 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.

如果您只想编辑安装路径,.bundle/config使用您喜欢的编辑器打开应该会显示vendor/bundle. 删除该行会将其恢复为默认值,而不会删除您可能拥有的其他配置。

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

此外,另一个不太常见的情况是您的系统范围设置被搞砸了。根据@NaoiseGolden:

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

我不得不.bundle从我的主文件夹中删除(rm -rf ~/.bundle)。您可以查看正在运行的配置bundle env

回答by u1860929

Try installing using

尝试安装使用

bundle install --system

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

我认为最初 bundle install 是使用--pathflag运行的,bundler 现在记得那个配置。

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.

在调用 bundle install 和 Bundler 运行时之间会记住一些选项。

对 bundle install 的后续调用会将 gems 安装到最初传递给--path的目录中。Bundler 运行时将在该位置寻找 gem。您可以通过运行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 answermentioned above.

编辑:正如在下面的评论中提到的,另外,这会安装 gems 系统。如果您使用 rvm 等来管理不同应用程序的环境,请查看上面提到的@IuriG 的答案

回答by Tim Moore

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

尝试运行bundle env。这将告诉您路径配置的设置位置。

回答by Rav.-

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).

首先,根据您的信息,您似乎已经安装了 rvm 和 rbenv。这是一个非常糟糕的主意。你必须删除其中一个(rbenv + bundler 对我来说就像一个魅力,没有尝试 rvm)。

In regard to your question check .bundle/configin 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: vendorin my case).

关于您的问题,请检查.bundle/config您的项目,因为该项目的所有 bundle 配置都在那里(如果它仍然被删除,您可以创建一个新的)。您可能想要添加此行(或更改它,如果它已经存在):BUNDLE_DISABLE_SHARED_GEMS: '0'为了共享宝石,它们会出现在您BUNDLE_PATH:设置的位置(BUNDLE_PATH: vendor在我的情况下)。

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

对于全局配置文件查看 ~/.bundle/config

Also this man page could be of use: bundle config

这个手册页也可能有用:bundle config

回答by Rokibul Hasan

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

要在系统范围内避免路径供应商/捆绑包中安装 Gem,只需在项目目录中运行以下命令

bundle install --system