title: Capistrano v3 could not find a Bundler
body: <p>I have a problem in deploying my App with Capistrano v3. When I run '$ cap production deploy' I see an error...</p>
  
  <pre><code> INFO [825ad68d] Running /usr/bin/env bundle --gemfile /home/username/www/myapp/releases/20131026181031/Gemfile --path /home/username/www/myapp/shared/bundle --deployment --quiet --binstubs /home/username/www/myapp/shared/bin --without development test on myhostname.com
  DEBUG [825ad68d] Command: cd /home/username/www/myapp/releases/20131026181031 &amp;&amp; ( RAILS_ENV=production /usr/bin/env bundle --gemfile /home/username/www/myapp/releases/20131026181031/Gemfile --path /home/username/www/myapp/shared/bundle --deployment --quiet --binstubs /home/username/www/myapp/shared/bin --without development test )
  DEBUG [825ad68d]    /usr/bin/env: 
  DEBUG [825ad68d]    bundle
  DEBUG [825ad68d]    : No such file or directory
  </code></pre>
  
  <p>But when I run the last command...</p>
  
  <pre><code>cd /home/username/www/myapp/releases/20131026181031 &amp;&amp; ( RAILS_ENV=production /usr/bin/env bundle --gemfile /home/username/www/myapp/releases/20131026181031/Gemfile --path /home/username/www/myapp/shared/bundle --deployment --quiet --binstubs /home/username/www/myapp/shared/bin --without development test )
  </code></pre>
  
  <p>... via ssh on my server I don't see any errors.</p>
  
  <p>Here is my server's environment:</p>
  
  <ul>
  <li>Ubuntu 13.04</li>
  <li>rvm 1.23.5 </li>
  <li>rubygems 1.8.25 </li>
  <li>Bundler 1.3.5 </li>
  <li>ruby 1.9.3p448</li>
  <li>capistrano (3.0.0)</li>
  <li>capistrano-bundler (1.0.0)</li>
  <li>capistrano-rails (1.0.0)</li>
  </ul>
  
  <p><strong>Here is a piece of my Gemfile which includes capistrano's gems</strong></p>
  
  <pre><code>...
  group :development do
    ...
    # Deploy with Capistrano
    gem 'capistrano', '~&gt; 3.0.0'
    gem 'capistrano-rails'
    gem 'capistrano-bundler'
  end
  ...
  </code></pre>
  
  <p>Please see below capistrano's configuration:</p>
  
  <p><strong>Capfile</strong></p>
  
  <pre><code>require 'capistrano/setup'
  require 'capistrano/deploy'
  require 'capistrano/bundler'
  require 'capistrano/rails/assets'
  require 'capistrano/rails/migrations'
  
  Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
  </code></pre>
  
  <p><strong>config/deploy.rb</strong></p>
  
  <pre><code>set :application, 'myapp'
  set :repo_url, "/home/username/repository/#{fetch(:application)}.git"
  set :deploy_to, "/home/usename/www/#{fetch(:application)}"
  set :scm, :git
  set :branch, "master"
  set :format, :pretty
  set :use_sudo, false
  
  set :linked_files, %w{config/database.yml}
  set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
  
  set :keep_releases, 5
  
  SSHKit.config.command_map[:rake]  = "bundle exec rake"
  SSHKit.config.command_map[:rails] = "bundle exec rails"
  
  namespace :deploy do
  
    desc 'Restart application'
    task :restart do
      on roles(:app), in: :sequence, wait: 5 do
        # Your restart mechanism here, for example:
        # execute :touch, release_path.join('tmp/restart.txt')
      end
    end
  
    after :restart, :clear_cache do
      on roles(:web), in: :groups, limit: 3, wait: 10 do
        # Here we can do anything such as:
        # within release_path do
        #   execute :rake, 'cache:clear'
        # end
      end
    end
  
    after :finishing, 'deploy:cleanup'
  end
  </code></pre>
  
  <p><strong>config/deploy/production.rb</strong></p>
  
  <pre><code>set :stage, :production
  
  set :bundle_gemfile, -&gt; { release_path.join('Gemfile') }
  set :bundle_dir, -&gt; { shared_path.join('bundle') }
  set :bundle_flags, '--deployment --quiet'
  set :bundle_without, %w{development test}.join(' ')
  set :bundle_binstubs, -&gt; { shared_path.join('bin') }
  set :bundle_roles, :all
  
  role :app, %w{myhostname.com}
  role :web, %w{myhostname.com}
  role :db,  %w{myhostname.com}
  
  server 'myhostname.com', user: 'username', roles: %w{web app}, my_property: :my_value
  
  fetch(:default_env).merge!(rails_env: :production)
  </code></pre>
  
  <p>Please help me.</p>
  
  <p><strong>SOLVED</strong></p>
  
  <p>I've solved my problem by following steps:</p>
  
  <p>Add capistrano-rvm into <strong>Gemfile</strong> and do </p>
  
  <pre><code>...
  group :development do
    ...
    gem 'capistrano', '~&gt; 3.0.0'
    gem 'capistrano-rails'
    gem 'capistrano-bundler'
    gem 'capistrano-rvm'
  end
  ...
  </code></pre>
  
  <p>Add this line into Capfile</p>
  
  <pre><code>require 'capistrano/rvm'
  </code></pre>
  
  <p>Add these lines into the <strong>deploy.rb</strong> file. </p>
  
  <pre><code>set :rvm_ruby_version, '1.9.3-p448'
  set :default_env, { rvm_bin_path: '~/.rvm/bin' }
  SSHKit.config.command_map[:rake] = "#{fetch(:default_env)[:rvm_bin_path]}/rvm ruby-#{fetch(:rvm_ruby_version)} do bundle exec rake"
  </code></pre>