Change PATH environment with Rails and Capistrano

Note to self.

When deploying my RubyOnRails applications with Capistrano and I get errors like this one

1
2
3
4
5
servers: ["app.myserver.com"]
[app.myserver.com] executing command
** [out :: app.myserver.com] sh: bundle: command not found
command finished in 31ms
servers: ["app.myserver.com"]    [app.myserver.com] executing command ** [out :: app.myserver.com] sh: bundle: command not found    command finished in 31ms

Capistrano executes the commands in a very basic shell so the $PATH environment are not the same as when you login through SSH.

One way to solve this is by setting PermitUserEnvironment to yes in /etc/sshd_config and then add the correct PATH to ~/.ssh/environment

I just found another way that was much easier :-)

In you config/deploy.rb add the following snippet

1
2
3
set :default_environment, {
  'PATH' => "/opt/ruby-enterprise/bin/:$PATH"
}

Thats it!

Cheers!

Posted in Programming, Rails, Ruby at June 1st, 2011. Trackback URI: trackback Tags: , , Written by: 

It's past my bedtime is using WP-Gravatar