Last Updated: February 25, 2016
·
754
· sck-v

How to use both rbenv and rvm with capistrano3

There are some cases when system environments on staging and production servers differs.
Lets assume that you have your production server running rvm and you want to try to setup rbenv on your staging.

Capistrano 3 provides great functionality for setting up and deploying your application for several environments. But if you will require both rbenv and rvm extensions it won't work.

But solution is pretty easy. Thanks to extendability of rake tasks as Capfile is a regular Rakefile.
Just add to your Capfile:

# ....
# some requires above

task :use_rvm do
  require 'capistrano/rvm'
end

task :use_rbenv do
  require 'capistrano/rbenv'
end

task production: :use_rvm
task staging: :use_rbenv

That's all! Now you can start deploying process with cap production deploy using rvm and cap staging deploy using rbenv.