Rails 3 -- Bundler/Capistrano Errors

Viewed 31034

I have a basic Rails 3 app working locally on my development box, but want to test out deploying early on to make sure everything works. I'm using Capistrano to deploy.

When I run cap deploy (after all the other necessary setup), it breaks on this command with this error:

[...]
* executing 'bundle:install'
* executing "bundle install --gemfile /var/www/trex/releases/20100917172521/Gemfile --path /var/www/trex/shared/bundle --deployment --quiet --without development test"

servers: ["www.[my domain].com"]
[www.[my domain].com] executing command
** [out :: www.[my domain].com] sh: bundle: command not found
command finished
[...]

So it looks like it can't find the bundle command on the server.

However, when I log in to the server...

$ ruby -v
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-linux]
$ rails -v
Rails 3.0.0
$ bundle -v
Bundler version 1.0.0

...the bundle command works just fine.

What could be going wrong?

-

(Furthermore, for completeness:)

$ which ruby
~/.rvm/rubies/ruby-1.9.2-p0/bin/ruby
$ which rails
~/.rvm/gems/ruby-1.9.2-p0/bin/rails
$ which bundle
~/.rvm/gems/ruby-1.9.2-p0/bin/bundle
8 Answers

It was my understanding that the bundle command is not found because the PATH variable, defined in the user's ~/.bash_profile, isn't loaded by Capistrano.

To get around this I have created a task :bundle_gems.

task :bundle_gems do
    run "cd #{deploy_to}/current && export PATH=/usr/local/pgsql/bin:/opt/ruby-enterprise-X.X.X/bin:$PATH && bundle install vendor/gems"
end

Note that I also include the path to PostgreSQL binaries - installation of the pg gem was failing because they could not be found, even when bundle could be found.

This seems like a messy approach, though. Presumably there is a more 'global' place to define paths to binaries that I don't know about.

Update 23/12

To add a directory to $PATH for all users: https://serverfault.com/questions/102932/adding-a-directory-to-path-in-centos

However this still won't be loaded because it is a non-interactive non-login shell.

One suggestion was to add the paths to /etc/bashrc: How do I set $PATH such that `ssh user@host command` works?

However this also didn't work for me. I believe its because SSH doesn't load /etc/bashrc either.

Another suggestion was to edit ~/.ssh/environment: http://www.ruby-forum.com/topic/79248. However this seems almost as messy as specifying the paths in deploy.rb.

Related