Trying to install a rails app with Capistrano 3 and rbenv

心不动则不痛 提交于 2019-12-07 05:06:04

问题


I have a VPS setup with Ruby 2.1.1 installed and the same version is installed locally. My dev machine running 14.04 Ubuntu reports ruby -v = ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux] and rbenv -v = rbenv 0.4.0-97-gfe0b243.

I originally installed ruby on the server using knife solo but it seems like capistrano wants to take care of this.

When I run cap staging deploy I get an error

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

回答1:


Was also struggling with this problem for a long time. @Darmen's answer pointed me into the right direction:

1) Set the path for rbenv in Capfile. For Capistrano 3.2.1, this is:

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

Note (maybe obvious) that it has to be the path on the server, find it with:

which rbenv

(compare https://github.com/capistrano/rbenv for rbenv_custom_path syntax - slightly different from @Darmen's answer)

2) Set the correct rbenv version in capfile, e.g.,

set :rbenv_ruby, '2.1.2'

For me, I did not have to use the complete ruby version. It has to match the directory name in /.rbenv/versions

Hope that helps - took me ages... ;-)




回答2:


I solved the same problem setting :rbenv_path. Yours should be:

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

I also had to set the complete ruby version, like this:

set :rbenv_ruby, '2.1.1-p76' 



回答3:


try those commands from your dev machine:

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

Then try cap staging deploy again




回答4:


Try to use Ruby 2.1.0, seems that the problem is caused by some compatibility issue with 2.1.1.

Or try to update Capistrano to the latest release (if you haven't yet done).




回答5:


Is possible that you need run deploy:setup_config and then just a straight up deploy may work.

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



来源:https://stackoverflow.com/questions/23361546/trying-to-install-a-rails-app-with-capistrano-3-and-rbenv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!