`
阅读更多
Rails3里多了个Bundler工具。
它是一个Library管理工具,它提供了好的工具来管理你rails3项目依赖的gems。
$> bundle
这个命令会列出bundler提供给你的一些工具。
Tasks:
  bundle check        # Checks if the dependencies listed in Gemfile are satisfied by currently installed gems
  bundle exec         # Run the command in context of the bundle
  bundle help [TASK]  # Describe available tasks or one specific task
  bundle init         # Generates a Gemfile into the current working directory
  bundle install      # Install the current environment to the system
  bundle lock         # Locks the bundle to the current set of dependencies, including all child dependencies.
  bundle pack         # Packs all the gems to vendor/cache
  bundle show         # Shows all gems that are part of the bundle.
  bundle unlock       # Unlock the bundle. This allows gem versions to be changed

你只要在你的Gemfile文件里添加你项目所需的gems就可以了。

$> bundle pack
这个命令可以打包你的gems到vendor/cache目录下。然后你把项目给别的开发者,别人就可以使用:
$> bundle install
来安装项目依赖的gems了。

但是当你想把项目部署到生产环境的话,假如gems出现新版本,可能导致项目出现错误,这个时候,我们就需要锁定gem的版本。
$> bundle lock
这个命令会在rails的根目录下生成一个Gemfile.lock文件。类似于这样的:
---
dependencies:
- rails: = 3.0.0.beta
- sqlite3-ruby: ">= 0"
- pg: ">= 0"
specs:
- text-hyphen:
    version: 1.0.0
- builder:
    version: 2.1.2
- i18n:
    version: 0.3.3

当你在Gemfile文件里增加了一个新的gem,比如“hpricot”你运行:
$> bundle check
You changed your Gemfile after locking. Please relock using `bundle unlock`
想修改Gemfile必须先解锁Gemfile文件:
$> bundle unlock
然后才能修改,修改完再锁定。
$> bundle install
这条命令会自动安装Gemfile里的所有gem。
然后我们再检测:
$>bundle check
The Gemfile's dependencies are satisfied
这就安全了。
然后我们可以打包了:
$> bundle pack
Copying .gem files into vendor/cache
...
打包完以后,锁定我们的gems:
$> bundle lock
这下你就可以安全部署你的app了。

转自:http://www.cnblogs.com/orez88/articles/1852286.html
gem的写法可以具体参照:http://github.com/carlhuda/bundler
Bundler官网:http://gembundler.com

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics