Path issues when using Capistrano

I recently started using Capistrano on a personal project, which is hosted on a relatively plain Ubuntu box.

Capistrano wouldn’t do much, I kept getting errors about “bundle” not being found. Seems the newer versions of Rails and Capistrano prefix everything with “bundle” so the right Gems etc. are used.

Turns out there’s a problem with the path that my Capistrano scripts get when they ssh into the Linux machine. Seems there’s a different environment for interactive SSH sessions, and the non-interactive SSH sessions that Capistrano uses.

To diagnose this, I added this to my deploy.rb:

desc "Echo environment vars"
namespace :env do
task :echo do
run "echo printing out cap info on remote server"
run "echo $PATH"
run "printenv"

Which when I do cap env:echo tells me the path that my Capistrano scripts see – which crucially doesn’t include /var/lib/gems/1.8/bin.

Turns out you set the environment in ~/.ssh/environment, adding a PATH line in the normal way.

But then you need to edit /etc/ssh/sshd_config and add a line

PermitUserEnvironment yes

And restart SSH.

After that your Cap deployments will be smooth…

Comments 1

  1. An quicker and easier way of diagnosing these kind of errors is to the use the Capistrano ‘shell’ task (e.g. the command ‘cap shell’), which gives you an interactive shell on the target system, with the Capistrano environment that used for deployment. For example:

    $ cap shell
    > echo $PATH
    /usr/local/sbin:/usr/local/bin:/usr/sbin: ….

Leave a Reply

Your email address will not be published. Required fields are marked *