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
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... ;-)
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With