尝试使用Capistrano 3和rbenv安装rails应用程序

时间:2014-04-29 10:05:28

标签: ruby-on-rails ruby-on-rails-4 capistrano rbenv

我安装了Ruby 2.1.1的VPS设置,并在本地安装了相同的版本。我的dev机器运行14.04 Ubuntu报告ruby -v = ruby​​ 2.1.1p76(2014-02-24修订版45161)[x86_64-linux]和rbenv -v = rbenv 0.4.0-97-gfe0b243。

我最初使用刀独奏在服务器上安装了ruby,但似乎capistrano想要照顾它。

当我运行cap staging deploy时,我收到错误

rbenv: cap: command not found
The `cap' command exists in these Ruby versions:  2.1.0

的Gemfile

group :development do
 gem 'capistrano', github: 'capistrano/capistrano', ref: 'master'
 gem 'capistrano-rails', github: 'capistrano/rails', ref: 'master'
 gem 'capistrano-bundler'
 gem 'capistrano-rbenv', "~> 2.0"
end

Capfile

require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rbenv'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'

deploy.rb

set :rbenv_type, :system
set :rbenv_ruby, '2.1.1'
set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"
set :rbenv_map_bins, %w{rake gem bundle ruby rails}
set :rbenv_roles, :all # default value

gem env

RubyGems Environment:
  - RUBYGEMS VERSION: 2.2.2
  - RUBY VERSION: 2.1.1 (2014-02-24 patchlevel 76) [x86_64-linux]
  - INSTALLATION DIRECTORY: /home/mark/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0
  - RUBY EXECUTABLE: /home/mark/.rbenv/versions/2.1.1/bin/ruby
  - EXECUTABLE DIRECTORY: /home/mark/.rbenv/versions/2.1.1/bin
  - SPEC CACHE DIRECTORY: /home/mark/.gem/specs
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /home/mark/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0
     - /home/mark/.gem/ruby/2.1.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
     - "gem" => "--no-ri --no-rdoc"
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /home/mark/.rbenv/versions/2.1.1/bin

5 个答案:

答案 0 :(得分:11)

很长一段时间也在努力解决这个问题。 @Darmen的回答指出了我正确的方向:

1)在Capfile中设置rbenv的路径。对于Capistrano 3.2.1,这是:

set :rbenv_custom_path, '/home/deploy/.rbenv/'

注意(可能很明显)它必须是服务器上的路径,找到它:

which rbenv

(比较https://github.com/capistrano/rbenv的rbenv_custom_path语法 - 与@ Darmen的答案略有不同)

2)在capfile中设置正确的rbenv版本,例如,

set :rbenv_ruby, '2.1.2'

对我来说,我没有必要使用完整的ruby版本。它必须匹配/.rbenv/versions

中的目录名称

希望有所帮助 - 把我带走了......; - )

答案 1 :(得分:1)

我解决了设置:rbenv_path的同样问题。 你的应该是:

set :rbenv_path, '/home/mark/.rbenv/'

我还必须设置完整的ruby版本,如下所示:

set :rbenv_ruby, '2.1.1-p76' 

答案 2 :(得分:0)

从您的开发机器尝试这些命令:

cd /path/to/your/application/root
gem uninstall capistrano
gem uninstall capistrano-rails
gem uninstall capistrano-bundler
gem uninstall capistrano-rbenv
# select "All versions" everytimes
bundle
# Verify that all capistrano gems are installed
rbenv rehash

然后再次尝试cap staging deploy

答案 3 :(得分:0)

尝试使用Ruby 2.1.0,似乎问题是由2.1.1的兼容性问题引起的。

或尝试将Capistrano更新为latest release(如果您尚未更新)。

答案 4 :(得分:0)

您可能需要运行deploy:setup_config,然后只需直接部署即可。

namespace :logs do desc "tail rails logs" task :tail_rails do on roles(:app) do execute "tail -f #{shared_path}/log/#{fetch(:rails_env)}.log" end end end