Rails 3 - Bundler/Capistrano错误

T.J*_*uck 53 capistrano ruby-on-rails bundler ruby-on-rails-3

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

当我运行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
[...]
Run Code Online (Sandbox Code Playgroud)

所以看起来它无法bundle在服务器上找到命令.

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

$ 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
Run Code Online (Sandbox Code Playgroud)

... bundle命令工作正常.

怎么可能出错?

-

(此外,为了完整:)

$ 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
Run Code Online (Sandbox Code Playgroud)

T.J*_*uck 89

更新:

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


原始答案:

好吧,虽然我没有cap deploy完成工作,但我确实解决了这个问题.问题是Capistrano尝试使用与RVM路径不同的Bundler(和其他宝石)路径.

通过做检查Capistrano的路径cap shell,然后echo $PATH.你可能会看到你的标准/usr/local/bin/usr/bin,但是这不是在那里RVM有捆扎机,等,存储.

编辑您的Capistrano config/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
Run Code Online (Sandbox Code Playgroud)

这终于让Capistrano看到Bundler并开始适当地加载宝石.

  • 最近有一段时间,情况发生了变化.你现在可以只做gem install rvm-capistrano来解决这个问题 (2认同)

小智 26

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

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

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

$ ssh user@123.amazonaws.com ls
.bashrc loaded
git
file1
file2
Run Code Online (Sandbox Code Playgroud)


小智 11

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


Rus*_*ssK 7

最后一行应该是

set :rvm_type, :user
Run Code Online (Sandbox Code Playgroud)

也就是说,用户必须是符号而不是变量,否则你就会得到

undefined local variable or method `user'
Run Code Online (Sandbox Code Playgroud)


hip*_*ker 7

没有rvm/capistrano为我工作.我找到的最佳解决方案是添加deploy.rb文件以下行(它适用于非系统范围的RVM):

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

  • 嗯......现在收到'sh:source:not found'错误. (4认同)