bundle install 命令

Bundle介绍:

Rails 3中引入Bundle来管理项目中所有gem依赖,该命令只能在一个含有Gemfile的目录下执行,如rails 3项目的根目录。


关于Gemfile和Gemfile.lock

所有Ruby项目的信赖包都在Gemfile中进行配置,不再像以往那样,通过require来查找。Rails 3中如果需要require某个gem包,必须通过修改Gemfile文件来管理。

Gemfile.lock则用来记录本机目前所有依赖的Ruby Gems及其版本。所以强烈建议将该文件放入版本控制器,从而保证大家基于同一环境下工作。


Bundle命令详解:


# 显示所有的依赖包
$ bundle show


# 显示指定gem包的安装位置
$ bundle show [gemname]


# 检查系统中缺少那些项目以来的gem包
# 注:如果系统中存在所有项目以来的包,则会输出:The Gemfile's dependencies are satisfied
$ bundle check


# 安装项目依赖的所有gem包
# 注:此命令会尝试更新系统中已存在的gem包
$ bundle install


# 安装指定的gem包
$ bundle install [gemname]


# 更新系统中存在的项目依赖包,并同时更新项目Gemfile.lock文件
$ bundle update


# 更新系统中指定的gem包信息,并同时更新项目Gemfile.lock中指定的包信息
$ bundle update [gemname]

 

# 向项目中添加新的gem包引用
$ gem [gemname], [ver]


# 你还可以指定包依赖关系
$ gem [gemname], :require => [dependence_gemname]


# 你甚至还可以指定gem包的git源
$ gem [gemname], :git => [git_source_url]


# 锁定当前环境
# 可以使用bundle lock来锁定当前环境,这样便不能通过bundle update来更新依赖包的版本,保证了统一的环境
$ bundle lock


# 解除锁定
$ bundle unlock


# 打包当装环境
# bundle package会把当前所有信赖的包都放到 ./vendor/cache/ 目录下,发布时可用来保证包版本的一致性。
$ bundle package


Make sure all dependencies in your Gemfile are available to your application.
$ bundle install [--binstubs=PATH] [--clean] [--deployment] [--frozen]
                 [--full-index] [--gemfile=FILE] [--local] [--no-cache]
                 [--no-prune] [--path=PATH] [--quiet] [--shebang=STRING]
                 [--standalone=ARRAY] [--system] [--without=GROUP GROUP]
                 [--trust-policy=SECURITYLEVEL]

Options:

--binstubs: Generate bin stubs for bundled gems to ./bin

--clean: Run bundle clean automatically after install

--deployment: Install using defaults tuned for deployment environments

--frozen: Do not allow the Gemfile.lock to be updated after this install

--full-index: Use the rubygems modern index instead of the API endpoint

--gemfile: Use the specified gemfile instead of Gemfile

--jobs: Install gems using parallel workers.

--local: Do not attempt to fetch gems remotely and use the gem cache instead

--no-cache: Don't update the existing gem cache.

--no-prune: Don't remove stale gems from the cache.

--path: Specify a different path than the system default ($BUNDLE_PATH or $GEM_HOME). Bundler will remember this value for future installs on this machine

--quiet: Only output warnings and errors.

--retry: Retry network and git requests that have failed.

--shebang: Specify a different shebang executable name than the default (usually 'ruby')

--standalone: Make a bundle that can work without the Bundler runtime

--system: Install to the system location ($BUNDLE_PATH or $GEM_HOME) even if the bundle was previously installed somewhere else for this application

--trust-policy: Sets level of security when dealing with signed gems. Accepts `LowSecurity`, `MediumSecurity` and `HighSecurity` as values.

--without: Exclude gems that are part of the specified named group.

Gems will be installed to your default system location for gems. If your system gems are stored in a root-owned location (such as in Mac OSX), bundle will ask for your root password to install them there.

While installing gems, Bundler will check vendor/cache and then your system's gems. If a gem isn't cached or installed, Bundler will try to install it from the sources you have declared in your Gemfile.

The --system option is the default. Pass it to switch back after using the --path option as described below.

Install your dependencies, even gems that are already installed to your system gems, to a location other than your system's gem repository. In this case, install them to  vendor/bundle.
$ bundle install --path vendor/bundle
Further  bundle commands or calls to  Bundler.setup or  Bundler.require will remember this location.
Learn More: Bundler.setup Learn More: Bundler.require
Install all dependencies except those in groups that are explicitly excluded.
$ bundle install --without development test
Learn More: Groups
Install all dependencies on to a production server. Do  not use this flag on a development machine.
$ bundle install --deployment

The --deployment flag activates a number of deployment-friendly conventions:

  • Isolate all gems into vendor/bundle
  • Require an up-to-date Gemfile.lock
  • If bundle package was run, do not fetch gems from rubygems.org. Instead, only use gems in the checked in vendor/cache
Learn More: Deploying
Install gems parallely by starting the number of workers specificed.
$ bundle install --jobs 4
Retry failed network or git requests.
$ bundle install --retry 3





你可能感兴趣的:(项目管理)