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

mar*_*cks 5 capistrano ruby-on-rails rbenv ruby-on-rails-4

我安装了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
Run Code Online (Sandbox Code Playgroud)

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

Capfile

require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rbenv'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
Run Code Online (Sandbox Code Playgroud)

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

宝石环境

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

rub*_*y24 11

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

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

set :rbenv_custom_path, '/home/deploy/.rbenv/'
Run Code Online (Sandbox Code Playgroud)

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

which rbenv
Run Code Online (Sandbox Code Playgroud)

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

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

set :rbenv_ruby, '2.1.2'
Run Code Online (Sandbox Code Playgroud)

对我来说,我没有必要使用完整的红宝石版本.它必须匹配/.rbenv/versions中的目录名称

希望有所帮助 - 带我年龄...... ;-)


Ben*_*enj 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
Run Code Online (Sandbox Code Playgroud)

然后再试cap staging deploy一次