markhorrocks
markhorrocks

Reputation: 1518

Trying to install a rails app with Capistrano 3 and rbenv

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

Upvotes: 5

Views: 6194

Answers (5)

ruby24
ruby24

Reputation: 309

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... ;-)

Upvotes: 11

Darme
Darme

Reputation: 7083

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' 

Upvotes: 1

Benjamin RD
Benjamin RD

Reputation: 12034

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

Upvotes: 0

Silverstorm
Silverstorm

Reputation: 15845

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).

Upvotes: 0

Benjamin Bouchet
Benjamin Bouchet

Reputation: 13181

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

Upvotes: 0

Related Questions