Capistrano 'Bundle Not Found' Error During Deployment

12,343

Solution 1

To avoide such problem you should have most recent versions of RVM (currently it is 1.13.5) installed in both places: locally and on remote server.

Next, check if your deploy.rb has

require "rvm/capistrano"
require "bundler/capistrano"

This line is not needed anymore:

$:.unshift(File.expand_path('./lib', ENV['rvm_path']))

Hope this will help

Solution 2

Ok, I've recently had some experience with this. Looks like there are a couple of ways that this problem can be solved. First, you can determine if in fact the remote execution (via Capistrano) is what's messed up vs. the host itself. Looks like you've done this with the Capistrano remote shell:

$ cap shell 
  > echo $PATH

Good. I'll bet when you login to the machine and 'echo $PATH' there, the right stuff comes out... same here.

I've found two ways to fix this: One is to enable the environment execution in the remote host's ssh daemon. In theory this would work, but I didn't want to ask the sysadmin if it was ok to open this up. You basically edit the ssh configuration files to set the 'PermitUserEnvironment' to 'yes' and add the required environment settings to the deploy user's ~/.ssh/environment file -- your system-specific man pages are probably better than my trying to generalize.

I opted for what seems rather hackish, and has the drawback that it is global for all hosts you deploy the app to (so if your ruby / gems locations are different on different hosts, this won't work) -- but: I added the default_environment settings to the config/deploy.rb script:

set :default_environment, {
    'PATH' => "/usr/local/bin:/bin:/usr/bin:/bin:/<ruby-dir>/bin",
    'GEM_HOME' => '<ruby-dir>/lib/ruby/gems/1.8',
    'GEM_PATH' => '<ruby-dir>lib/ruby/gems/1.8',
    'BUNDLE_PATH' => '<ruby-dir>/lib/ruby/gems/1.8/gems'  
}


AMMENDED: It isn't so 'hackish' if you consider the following:  
  - The environment-specific deploy scripts (deploy/foo.rb) can 
    override the default in deploy.rb  
  - PermitUserEnvironment hides the configuration deep in the 
    .ssh directory of the deploy user; :default_environment at
    least exposes it in the checked-in sources.

This also solves the problem of not being able to do remote rake tasks, etc., via Capistrano. Be aware that the Capistrano gem, at least the version I have and with my deploy set up in the "standard" way, will install the gems into the /shared/bundle directory, which gets picked up by the app. The method I described requires a minimal subset of gems in the system directories referenced by the default environment so that the remote Capistrano commands can execute bundle, rake, etc.

You didn't say if you were using RVM (my solution doesn't); however, this solution is very close to one of the recommended RVM solutions. Alternately, you could just use the 'rvm/capistrano' solution; look for RVM Capistrano integration on the RVM website for more details.

Solution 3

Are you using RVM ?

DaneS some possible solutions:

place

require "bundler/capistrano"

in your script as bundler now has support for capistrano https://github.com/carlhuda/bundler/blob/1-0-stable/lib/bundler/capistrano.rb

And maybe

before "deploy:cold", 
    "deploy:install_bundler"

task :install_bundler, :roles => :app do
    run "type -P bundle &>/dev/null || { gem install bundler --no-rdoc --no-ri; }"
end

The install_bundler task will only be installed if not found.

Solution 4

Have you manually installed the bundler gem on the remote box? You can't use the bundle command or install any bundles until you do.

Share:
12,343

Related videos on Youtube

DaneS
Author by

DaneS

Updated on May 16, 2020

Comments

  • DaneS
    DaneS almost 4 years

    When I run cap deploy:update I get the error below, indicating that bundle is not found. When I run echo $PATH from cap shell the /var/lib/gems/1.9.1/bin path which contains bundle is missing, however, this path is in both /etc/profile and ~/.bashrc. Anyone know how to solve this problem?

        [192.168.10.100] executing command
    *** [err :: 192.168.10.100] sh:
    *** [err :: 192.168.10.100] bundle: not found
    *** [err :: 192.168.10.100]
        command finished in 25ms
    failed: "sh -c 'bundle install --gemfile /data/www/apps/my_app/releases/201104
    04163717/Gemfile --path /data/www/apps/my_apps/shared/bundle --deployment --qui
    et --without development test'" on 192.168.10.100
    
  • Patrick Peak
    Patrick Peak over 12 years
    This was helpful. In my case, I was having a similar problem where bundler was found, but rake was not, even when running `bundle exec rake'. I did a short modification to the environment that looked like this: set :default_environment, { 'PATH' => "/opt/ruby-ee/bin:$PATH" }
  • Paul
    Paul over 12 years
    I tried these techniques and got the same errors still. any other options?
  • Macdiesel
    Macdiesel almost 12 years
    It may be worth noting that ubuntu now puts an early exit in the .bashrc script so it may not be loading your environment if you are appending path variables to the end. You may want to try adding environment variables to the beginning of the file
  • Bishma Stornelli
    Bishma Stornelli over 11 years
    Don't forget to add 'gem "rvm-capistrano"' to your Gemfile
  • Snowcrash
    Snowcrash almost 11 years
    I just get "the task deploy:cold' does not exist" when I use require "rvm/capistrano". However, require "capistrano"` seems to work for me.

Related