deploy.rb: undefined local variable or method `home` for main:Object

capistrano3, ruby

Solution

I don't think Capistrano will create local variables for you, but you can do so yourself:

domain = "mydomain"
home = "/home/myuser"

set :domain, domain
set :home, home
set :deploy_to, "#{home}/#{domain}"

Alternatively, you can use `fetch`, the counterpart to `set`:

set :domain, "mydomain"
set :home, "/home/myuser"
set :deploy_to, "#{fetch(:home)}/#{fetch(:domain)}"

Problem

I know there are a lot of questions regarding this error message, but I couldn't find one where this error is happening in the same context as mine. I'm trying to migrate a previously working Capistrano configuration from version 2 to Capistrano 3. Unfortunately, calling `cap production deploy --dry-run` generates the error ``` cap aborted! undefined local variable or method `home' for main:Object /myapp/config/deploy.rb:6:in `<top (required)>' ``` Here's the content of `deploy.rb` up to line 6 where the error occurs: ``` set :user, "myuser" set :application, "myapp" set :domain, "mydomain" set :repository, "git@github.com:acme/myapp.git" set :home, "/home/myuser" set :deploy_to, "#{home}/#{domain}" ``` I don't know much about Ruby, but from what I've gathered, the colon means these are symbols, not variables, and in the Capistrano documentation they're using the same syntax to define "variables" (see paragraph 5 "Set the shared information in deploy.rb")? The deploy script ran flawlessly on OS X with Ruby 2.0.0p247 and Capistrano 2.9.0. Now on CentOS with Ruby 1.9.3p545 and Capistrano 3.1.0, the error mentioned above occurs. I've made several changes to the `Capfile` to get it running with Capistrano 3, but left the `deploy.rb` untouched, hoping it would work.

Original source