Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 265
markhorrocks Avatar asked Apr 29 '14 10:04

markhorrocks


2 Answers

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

like image 72
ruby24 Avatar answered Oct 27 '22 01:10

ruby24


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' 
like image 26
Darme Avatar answered Oct 27 '22 01:10

Darme