Whenever give ``require': cannot load such file -- bundler/setup` error in production server

2.3k Views Asked by At

Im trying to setup whenever gem in my Ubuntu 14.04 server. In my local machine it works fine. I use capistrano to deploy the site. I use rbenv in the server. But when installing passenger it installs Ruby 1.9 which I do not use. Only use rbenv. Here's my shcedule.rb :

set :output, "#{path}/log/cron.log"

every 30.minutes do
    runner 'UploadmailWorker.perform_async'
end

every 12.hours do
    runner 'SubscriptionWorker.perform_async'
end

every :month do
    runner 'PaysellerWorker.perform_async'
end

My deploy.rb :

set :default_environment, {
  'PATH' => "$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH"
}

set :whenever_roles,        ->{ :app }
set :whenever_command,      ->{ [:bundle, :exec, :whenever] }
set :whenever_command_environment_variables, ->{ {} }
set :whenever_identifier,   ->{ fetch :application }
set :whenever_environment,  ->{ fetch :rails_env, fetch(:stage, "production") }
set :whenever_variables,    ->{ "environment=#{fetch :whenever_environment}" }
set :whenever_update_flags, ->{ "--update-crontab #{fetch :whenever_identifier} --set #{fetch :whenever_variables}" }
set :whenever_clear_flags,  ->{ "--clear-crontab #{fetch :whenever_identifier}" }

namespace :deploy do

    desc 'Restart application'
    task :restart do
        on roles(:app), in: :sequence, wait: 5 do
            execute :touch, release_path.join('tmp/restart.txt')
        end
    end

    after :publishing, 'deploy:restart'
    after :finishing, 'deploy:cleanup'
end

After deploying, the whenever does not work. In the cron.log I find this error :

/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- bundler/setup (LoadError)
        from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from /home/deploy/istockseller/releases/20150519112817/config/boot.rb:3:in `<top (required)>'
        from bin/rails:7:in `require_relative'
        from bin/rails:7:in `<main>'

How can I fix that?

2

There are 2 best solutions below

2
On

/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'

Don't be confused, by this line. This is ruby library that get to be install for every ubuntu instances, so you can execute ruby commands.

You need cd to you project and install bundler.

Run this.

cd /to/your/project
[sudo] gem install bundler
bundle install

Update info for rbenv

echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile

Use ~/.bashrc on Ubuntu, or ~/.zshrc for Zsh

$ type rbenv
#=> "rbenv is a function"
0
On

I also had this error:

custom_require.rb:36:in `require': cannot load such file -- bundler/setup (LoadError)

after investigating the issue the PATH shell variable was diferent in the cronb job and did not had rbenv stuff in it

changed the crontab manually with crontab -e

and added at the crontab lines

... && PATH = my_complete_path RAILS_ENV=production  bin/rails ... ... 

after that the cronjob started working ...

I dont consider this a good answer but a hack to get it working. Maybe it helps someone.