Ruby-on-rails Rails 3 -- Bundler/Capistrano 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3737678/
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:13:22  来源:igfitidea点击:

Rails 3 -- Bundler/Capistrano Errors

ruby-on-railsruby-on-rails-3capistranobundler

提问by T.J. Schuck

I have a basic Rails 3 app working locally on my development box, but want to test out deploying early on to make sure everything works. I'm using Capistrano to deploy.

我有一个基本的 Rails 3 应用程序在我的开发箱上本地工作,但想测试早期部署以确保一切正常。我正在使用 Capistrano 进行部署。

When I run cap deploy(after all the other necessary setup), it breaks on this command with this error:

当我运行时cap deploy(在所有其他必要的设置之后),它在这个命令上中断并出现以下错误:

[...]
* executing 'bundle:install'
* executing "bundle install --gemfile /var/www/trex/releases/20100917172521/Gemfile --path /var/www/trex/shared/bundle --deployment --quiet --without development test"

servers: ["www.[my domain].com"]
[www.[my domain].com] executing command
** [out :: www.[my domain].com] sh: bundle: command not found
command finished
[...]

So it looks like it can't find the bundlecommand on the server.

所以看起来它bundle在服务器上找不到命令。

However, when I log in to the server...

但是,当我登录到服务器...

$ ruby -v
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-linux]
$ rails -v
Rails 3.0.0
$ bundle -v
Bundler version 1.0.0

...the bundlecommand works just fine.

...bundle命令工作得很好。

What could be going wrong?

可能出什么问题了?

-

——

(Furthermore, for completeness:)

(此外,为了完整性:)

$ which ruby
~/.rvm/rubies/ruby-1.9.2-p0/bin/ruby
$ which rails
~/.rvm/gems/ruby-1.9.2-p0/bin/rails
$ which bundle
~/.rvm/gems/ruby-1.9.2-p0/bin/bundle

回答by T.J. Schuck

UPDATE:

更新:

For RVM >= 1.11.3, you should now just use the rvm-capistrano gem. For older RVM >= 1.0.1, the answer below still applies.

对于 RVM >= 1.11.3,您现在应该只使用rvm-capistrano gem。对于较旧的 RVM >= 1.0.1,下面的答案仍然适用。



ORIGINAL ANSWER:

原始答案:

Okay, though I stillhaven't gotten a full cap deployto work, I did fix thisproblem. The problem was Capistrano trying to use a different path for Bundler (and other gems) than the RVM paths.

好吧,虽然我没有完全cap deploy投入工作,但我确实解决了这个问题。问题是 Capistrano 试图为 Bundler(和其他 gem)使用与 RVM 路径不同的路径。

Check your Capistrano path by doing cap shell, then echo $PATH. You'll probably see your standard /usr/local/binand /usr/bin, but that's not where RVM has Bundler, et al., stored.

执行cap shell,然后检查您的 Capistrano 路径echo $PATH。您可能会看到您的标准/usr/local/bin/usr/bin,但这不是 RVM 存储 Bundler 等人的地方。

Edit your Capistrano config/deploy.rbfile, and add the following lines, per these instructions:

编辑您的 Capistranoconfig/deploy.rb文件,并按照以下说明添加以下行:

# Add RVM's lib directory to the load path.
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))

# Load RVM's capistrano plugin.    
require "rvm/capistrano"

set :rvm_ruby_string, '1.9.2'
set :rvm_type, :user  # Don't use system-wide RVM

That finally got Capistrano to see Bundler and start loading gems appropriately.

这最终让 Capistrano 看到了 Bundler 并开始适当地加载 gem。

回答by Pete Campbell

Bundler isn't found because .bash_profile is not being loaded and thus your PATH is wrong. This is probably because you have the RVM script in .bash_profile.

未找到 Bundler,因为 .bash_profile 未加载,因此您的 PATH 错误。这可能是因为您在 .bash_profile 中有 RVM 脚本。

The simple answer is to move the RVM script from .bash_profile to .bashrc and Capistrano should be able to find it (also verify that .bash_profile sources .bashrc).

简单的答案是将 RVM 脚本从 .bash_profile 移动到 .bashrc 并且 Capistrano 应该能够找到它(同时验证 .bash_profile 源 .bashrc)。

Capistrano uses SSH to execute commands on the server via a non-interactive shell. This shell session will source .bashrc but not .bash_profile. I added an ECHO statement to both and ran an LS via SSH. You can see in the results below that only .bashrc is sourced:

Capistrano 使用 SSH 通过非交互式 shell在服务器上执行命令。此 shell 会话将提供.bashrc 而不是 .bash_profile。我向两者添加了一个 ECHO 语句并通过 SSH 运行了一个 LS。您可以在下面的结果中看到,只有 .bashrc 是来源:

$ ssh [email protected] ls
.bashrc loaded
git
file1
file2

回答by Lelon

I had an identical problem using rbenv. The solution was to take the rbenv specific lines from the bottom of my .bashrc file and put them at the top. The first line of my .bashrc file was returning aborting if the shell wasn't running in interactive mode.

我在使用 rbenv 时遇到了同样的问题。解决方案是从我的 .bashrc 文件底部取出 rbenv 特定行并将它们放在顶部。如果 shell 没有在交互模式下运行,我的 .bashrc 文件的第一行将返回中止。

回答by hipertracker

No rvm/capistranoworked for me. The best solution I found was adding to deploy.rbfile the following line (it's for non system-wide RVM):

没有rvm/capistrano对我来说有效。我发现的最佳解决方案是将以deploy.rb下行添加到文件中(它用于非系统范围的 RVM):

set :bundle_cmd, 'source $HOME/.bash_profile && bundle'

set :bundle_cmd, 'source $HOME/.bash_profile && bundle'

回答by RussK

That last line should actually be

最后一行实际上应该是

set :rvm_type, :user

that is, user must be a symbol and not a variable, otherwise you'll get

也就是说, user 必须是一个符号而不是一个变量,否则你会得到

undefined local variable or method `user'

回答by Sai Perchard

It was my understanding that the bundle command is not found because the PATH variable, defined in the user's ~/.bash_profile, isn't loaded by Capistrano.

我的理解是找不到 bundle 命令,因为在用户的 ~/.bash_profile 中定义的 PATH 变量不是由 Capistrano 加载的。

To get around this I have created a task :bundle_gems.

为了解决这个问题,我创建了一个任务:bundle_gems。

task :bundle_gems do
    run "cd #{deploy_to}/current && export PATH=/usr/local/pgsql/bin:/opt/ruby-enterprise-X.X.X/bin:$PATH && bundle install vendor/gems"
end

Note that I also include the path to PostgreSQL binaries - installation of the pg gem was failing because they could not be found, even when bundle could be found.

请注意,我还包含了 PostgreSQL 二进制文件的路径 - pg gem 的安装失败,因为找不到它们,即使可以找到包。

This seems like a messy approach, though. Presumably there is a more 'global' place to define paths to binaries that I don't know about.

不过,这似乎是一种混乱的方法。大概有一个更“全局”的地方来定义我不知道的二进制文件的路径。

Update 23/12

23/12 更新

To add a directory to $PATH for all users: https://serverfault.com/questions/102932/adding-a-directory-to-path-in-centos

为所有用户添加一个目录到 $PATH:https: //serverfault.com/questions/102932/adding-a-directory-to-path-in-centos

However this still won't be loaded because it is a non-interactive non-login shell.

然而,这仍然不会被加载,因为它是一个非交互式非登录 shell。

One suggestion was to add the paths to /etc/bashrc: How do I set $PATH such that `ssh user@host command` works?

一个建议是将路径添加到 /etc/bashrc:如何设置 $PATH 以使 `ssh user@host command` 有效?

However this also didn't work for me. I believe its because SSH doesn't load /etc/bashrc either.

然而,这对我也不起作用。我相信这是因为 SSH 也不加载 /etc/bashrc 。

Another suggestion was to edit ~/.ssh/environment: http://www.ruby-forum.com/topic/79248. However this seems almost as messy as specifying the paths in deploy.rb.

另一个建议是编辑 ~/.ssh/environment: http://www.ruby-forum.com/topic/79248。然而,这看起来几乎和在 deploy.rb 中指定路径一样混乱。

回答by Nesha Zoric

This one worked for me:

这个对我有用:

set :bundle_cmd, 'source $HOME/.bash_profile && bundle'

set :bundle_cmd, 'source $HOME/.bash_profile && bundle'

回答by Grant Sayer

I tried a number of the suggestions. Had problems with setting the paths in the deploy.rb file for the RVM environment. My final solution was to include the following:

我尝试了一些建议。在为 RVM 环境设置 deploy.rb 文件中的路径时遇到问题。我的最终解决方案是包括以下内容:

In the config/deploy.rb file add:

在 config/deploy.rb 文件中添加:

require "bundler/capistrano"

Also in config/deploy.rb, or in my case config/production.rb as I was using the multistage option for Capistrano

同样在 config/deploy.rb 中,或者在我的情况下 config/production.rb 中,因为我使用 Capistrano 的多级选项

after "deploy", "rvm:trust_rvmrc"

This step simply ensures that we stop getting the 'do you want to trust the .rvmrc file' and it calls a task in the deploy.rb file such as:

这一步只是确保我们停止获取“您想信任 .rvmrc 文件吗”,它会调用 deploy.rb 文件中的一个任务,例如:

namespace :rvm do
   task :trust_rvmrc do
      run "rvm rvmrc trust #{release_path}"
   end
end

After putting in these slight changes I was able to run cap production deploywhich checked out the code; executed the asset pipeline deployment, linked up the release folder to current, executed bundle installand cleaned up.

在进行这些细微的更改后,我能够运行cap production deploy它检查了代码;执行资产管道部署,将发布文件夹链接到当前,执行bundle install和清理。