[翻译]  Capistrano 'Bundle Not Found' Error During Deployment

[CHINESE]  部署期间Capistrano'Bundle Not Found'错误

When I run cap deploy:update I get the error below, indicating that bundle is not found. When I run echo $PATH from cap shell the /var/lib/gems/1.9.1/bin path which contains bundle is missing, however, this path is in both /etc/profile and ~/.bashrc. Anyone know how to solve this problem?

当我运行cap deploy:update时我得到下面的错误,表明找不到bundle。当我从cap shell运行echo $ PATH时,缺少包含bundle的/var/lib/gems/1.9.1/bin路径,但是这个路径在/ etc / profile和〜/ .bashrc中。有谁知道如何解决这个问题?

    [] executing command
*** [err ::] sh:
*** [err ::] bundle: not found
*** [err ::]
    command finished in 25ms
failed: "sh -c 'bundle install --gemfile /data/www/apps/my_app/releases/201104
04163717/Gemfile --path /data/www/apps/my_apps/shared/bundle --deployment --qui
et --without development test'" on

4 个解决方案



To avoide such problem you should have most recent versions of RVM (currently it is 1.13.5) installed in both places: locally and on remote server.


Next, check if your deploy.rb has


require "rvm/capistrano"
require "bundler/capistrano"

This line is not needed anymore:


$:.unshift(File.expand_path('./lib', ENV['rvm_path']))

Hope this will help




Ok, I've recently had some experience with this. Looks like there are a couple of ways that this problem can be solved. First, you can determine if in fact the remote execution (via Capistrano) is what's messed up vs. the host itself. Looks like you've done this with the Capistrano remote shell:


$ cap shell 
  > echo $PATH

Good. I'll bet when you login to the machine and 'echo $PATH' there, the right stuff comes out... same here.

好。我敢打赌,当你登录到机器并在那里'echo $ PATH'时,正确的东西出来了......在这里也一样。

I've found two ways to fix this: One is to enable the environment execution in the remote host's ssh daemon. In theory this would work, but I didn't want to ask the sysadmin if it was ok to open this up. You basically edit the ssh configuration files to set the 'PermitUserEnvironment' to 'yes' and add the required environment settings to the deploy user's ~/.ssh/environment file -- your system-specific man pages are probably better than my trying to generalize.

我找到了两种解决方法:一种是在远程主机的ssh守护进程中启用环境执行。理论上这可行,但我不想问系统管理员是否可以打开它。您基本上编辑ssh配置文件以将'PermitUserEnvironment'设置为'yes'并将所需的环境设置添加到部署用户的〜/ .ssh / environment文件 - 您的系统特定手册页可能比我尝试概括更好。

I opted for what seems rather hackish, and has the drawback that it is global for all hosts you deploy the app to (so if your ruby / gems locations are different on different hosts, this won't work) -- but: I added the default_environment settings to the config/deploy.rb script:

我选择了看似相当hackish的东西,并且缺点是它为你部署应用程序的所有主机都是全局的(所以如果你的ruby / gems位置在不同的主机上不同,这将不起作用) - 但是:我添加了config / deploy.rb脚本的default_environment设置:

set :default_environment, {
    'PATH' => "/usr/local/bin:/bin:/usr/bin:/bin:/<ruby-dir>/bin",
    'GEM_HOME' => '<ruby-dir>/lib/ruby/gems/1.8',
    'GEM_PATH' => '<ruby-dir>lib/ruby/gems/1.8',
    'BUNDLE_PATH' => '<ruby-dir>/lib/ruby/gems/1.8/gems'  

AMMENDED: It isn't so 'hackish' if you consider the following:  
  - The environment-specific deploy scripts (deploy/foo.rb) can 
    override the default in deploy.rb  
  - PermitUserEnvironment hides the configuration deep in the 
    .ssh directory of the deploy user; :default_environment at
    least exposes it in the checked-in sources.

This also solves the problem of not being able to do remote rake tasks, etc., via Capistrano. Be aware that the Capistrano gem, at least the version I have and with my deploy set up in the "standard" way, will install the gems into the /shared/bundle directory, which gets picked up by the app. The method I described requires a minimal subset of gems in the system directories referenced by the default environment so that the remote Capistrano commands can execute bundle, rake, etc.

这也解决了无法通过Capistrano进行远程耙式任务等问题。请注意,Capistrano宝石,至少我拥有的版本以及以“标准”方式设置我的部署,会将宝石安装到/ shared / bundle目录中,该目录会被应用程序选中。我描述的方法需要在默认环境引用的系统目录中使用最小的gem子集,以便远程Capistrano命令可以执行bundle,rake等。

You didn't say if you were using RVM (my solution doesn't); however, this solution is very close to one of the recommended RVM solutions. Alternately, you could just use the 'rvm/capistrano' solution; look for RVM Capistrano integration on the RVM website for more details.

你没有说你是否在使用RVM(我的解决方案没有);但是,此解决方案非常接近推荐的RVM解决方案之一。或者,您可以使用'rvm / capistrano'解决方案;在RVM网站上寻找RVM Capistrano集成以获取更多详细信息。



Have you manually installed the bundler gem on the remote box? You can't use the bundle command or install any bundles until you do.




Are you using RVM ?


DaneS some possible solutions:




require "bundler/capistrano"

in your script as bundler now has support for capistrano https://github.com/carlhuda/bundler/blob/1-0-stable/lib/bundler/capistrano.rb

在你的脚本中,bundler现在支持capistrano https://github.com/carlhuda/bundler/blob/1-0-stable/lib/bundler/capistrano.rb

And maybe


before "deploy:cold", 

task :install_bundler, :roles => :app do
    run "type -P bundle &>/dev/null || { gem install bundler --no-rdoc --no-ri; }"

The install_bundler task will only be installed if not found.




© 2014-2018 ITdaan.com 粤ICP备14056181号