Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 -- Bundler/Capistrano Errors

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 
like image 626
T.J. Schuck Avatar asked Sep 17 '10 17:09

T.J. Schuck


2 Answers

UPDATE:

For RVM >= 1.11.3, you should now just use the rvm-capistrano gem. For older RVM >= 1.0.1, the answer below still applies.


ORIGINAL ANSWER:

Okay, though I still haven't gotten a full cap deploy to work, I did fix this problem. The problem was Capistrano trying to use a different path for Bundler (and other gems) than the RVM paths.

Check your Capistrano path by doing cap shell, then echo $PATH. You'll probably see your standard /usr/local/bin and /usr/bin, but that's not where RVM has Bundler, et al., stored.

Edit your Capistrano config/deploy.rb file, and add the following lines, per these instructions:

# Add RVM's lib directory to the load path. $:.unshift(File.expand_path('./lib', ENV['rvm_path']))  # Load RVM's capistrano plugin.     require "rvm/capistrano"  set :rvm_ruby_string, '1.9.2' set :rvm_type, :user  # Don't use system-wide RVM 

That finally got Capistrano to see Bundler and start loading gems appropriately.

like image 105
T.J. Schuck Avatar answered Sep 22 '22 23:09

T.J. Schuck


Bundler isn't found because .bash_profile is not being loaded and thus your PATH is wrong. This is probably because you have the RVM script in .bash_profile.

The simple answer is to move the RVM script from .bash_profile to .bashrc and Capistrano should be able to find it (also verify that .bash_profile sources .bashrc).

Capistrano uses SSH to execute commands on the server via a non-interactive shell. This shell session will source .bashrc but not .bash_profile. I added an ECHO statement to both and ran an LS via SSH. You can see in the results below that only .bashrc is sourced:

$ ssh [email protected] ls .bashrc loaded git file1 file2 
like image 23
Pete Campbell Avatar answered Sep 24 '22 23:09

Pete Campbell