Search code examples
ruby-on-railsrubyrvmcapistranorvm-capistrano

RVM / Cap / Bundler - bundle install could not find bundler


I'm running Capistrano with RVM, I'm trying to migrate part of our web app to a new server. I've done the cap deploy:setup and cap deploy:check, everything seems to be good. When I run my deploy though Im getting this error

triggering before callbacks for `deploy:finalize_update'
* 2016-02-12 10:48:56 executing `bundle:install'
* executing "cd /u/apps/platform934/releases/20160212174856 && bundle install --gemfile /u/apps/platform934/releases/20160212174856/Gemfile --path /u/apps/platform934/shared/bundle --deployment --quiet --without development test"
 servers: ["192.168.85.144"]
[192.168.85.144] executing command
** [out :: 192.168.85.144] /home/platform934/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:315:in `to_specs': Could not find 'bundler' (>= 0) among 11 total gem(s) (Gem::LoadError)
** [out :: 192.168.85.144] Checked in 'GEM_PATH=/home/platform934/.rvm/gems/ruby-1.9.3-p545@platform934:/home/platform934/.rvm/gems/ruby-1.9.3-p545@global', execute `gem env` for more information
** [out :: 192.168.85.144] from /home/platform934/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:324:in `to_spec'
** [out :: 192.168.85.144] from /home/platform934/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_gem.rb:64:in `gem'
** [out :: 192.168.85.144] from /usr/local/bin/bundle:18:in `<main>'
** [out :: 192.168.85.144] from /usr/local/bin/ruby_executable_hooks1.9.1:15:in `eval'
** [out :: 192.168.85.144] from /usr/local/bin/ruby_executable_hooks1.9.1:15:in `<main>'
command finished in 168ms
*** [deploy:update_code] rolling back
* executing "rm -rf /u/apps/platform934/releases/20160212174856; true"
servers: ["192.168.85.144"]
[192.168.85.144] executing command
command finished in 142ms
failed: "rvm_path=$HOME/.rvm $HOME/.rvm/bin/rvm-shell 'ruby-1.9.3-p545@platform934' -c 'cd /u/apps/platform934/releases/20160212174856 && bundle install --gemfile /u/apps/platform934/releases/20160212174856/Gemfile --path /u/apps/platform934/shared/bundle --deployment --quiet --without development test'" on 192.168.85.144

here is my deploy.rb file.

set :stages,        %w(staging production)¬
¬
set :default_stage, 'production'¬
require 'capistrano/ext/multistage'¬
¬
set :application, "platform934"¬
set :repository,  "[email protected]:foo"¬
set :scm,         :git¬
set :branch,      'master'¬
ssh_options[:forward_agent] = true¬
#set :user, "root"¬
#set :use_sudo, true¬
set :deploy_via, :remote_cache¬
set :ssh_options, { :forward_agent => true}¬
#set :git_enable_submodules, 1¬
default_run_options[:pty] = true¬

# RVM Setup¬
gem 'sass-rails',    '= 3.2.6'¬
#$:.unshift(File.expand_path('./lib', ENV['rvm_path'])) # Add RVM's lib directory to the load path.¬
require "bundler/capistrano"¬
require "rvm/capistrano"
set :rvm_ruby_string,  ENV['GEM_HOME'].gsub(/.*\//,"")¬
#set :rvm_ruby_string, '1.9.3@platform934'¬
set :rvm_type, :user¬
  before 'deploy', 'rvm:install_rvm' #install rvm on target¬
  before 'deploy', 'rvm:install_ruby' #install ruby on target¬
  before 'deploy:setup', 'rvm:install_rvm'¬
  before 'deploy:setup', 'rvm:install_ruby'¬
¬
⋅⋅⋅⋅¬
# Unicorn tasks from: http://blog.teachstreet.com/building-teachstreet/how-i-learned-to-stop-worrying-and-love-the-unicorn/¬
set :unicorn_pid, "#{shared_path}/pids/unicorn.pid"¬
namespace :unicorn do¬
desc "start unicorn"¬
task :start, :roles => :app, :except => { :no_release => true } do¬
run "cd #{current_path} && bundle exec unicorn -c #{current_path}/config/unicorn-#{rails_env}.rb -E #{rails_env} -D"¬
end¬
desc "stop unicorn"¬
task :stop, :roles => :app, :except => { :no_release => true } do¬
  run " kill `cat #{unicorn_pid}`"¬
end¬
desc "graceful stop unicorn"¬
task :graceful_stop, :roles => :app, :except => { :no_release => true } do¬
  run " kill -s QUIT `cat #{unicorn_pid}`"¬
end¬
desc "reload unicorn"¬
task :reload, :roles => :app, :except => { :no_release => true } do¬
  run " sleep 3;  kill -s USR2 `cat #{unicorn_pid}`"¬
end¬
⋅¬
after "deploy:restart", "unicorn:reload"¬
end¬
¬
namespace :rvm do¬
task :trust_rvmrc do¬
 run "rvm rvmrc trust #{release_path}"¬
end¬
after "deploy", "rvm:trust_rvmrc"¬
end¬

I'm not very experienced with rvm, Ive tried installing the gem manually but I don't know how to get it into that directory. I could really use help, I feel like I'm missing something incredibly easy and just cannot find the solution anywhere online that works for me.


Solution

  • RVM doesn't install automatically bundler gem after installing ruby. So each time you'll install a new version of Ruby via RVM you'll have to run gem install bundler command after.

    Another solution is to edit your rvmrc configs in ~/.rvmrc or /etc/rvmrc and add rvm_autoinstall_bundler_flag=1

    This line will force RVM to install bundler gem and run bundle install if Gemfile available.

    Hope it helps :)