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 checkYou changed your Gemfile after locking. Please relock using `bundle unlock`想修改Gemfile必须先解锁Gemfile文件:$> bundle unlock然后才能修改,修改完再锁定。$> bundle install这条命令会自动安装Gemfile里的所有gem。然后我们再检测:$>bundle checkThe Gemfile's dependencies are satisfied这就安全了。然后我们可以打包了:$> bundle packCopying .gem files into vendor/cache...打包完以后,锁定我们的gems:$> bundle lock这下你就可以安全部署你的app了。gem的写法可以具体参照:http://github.com/carlhuda/bundler Bundler官网:http://gembundler.com本文出自 “” 博客,请务必保留此出处