Rails and Passenger app deployment error: rake-13.0.6 Bundler::GemNotFound

Note that the server paths to Apache, Ruby, and your app web folder will vary depending on your operating system and server configuration.

After deploying a Rails app to a server environment via Capistrano, the following generic Phusion Passenger error screen is being shown:

I ssh to the server and check the Apache logs for errors:

➜ tail -f /etc/httpd/logs/error_log
...
App 29384 output: Error: The application encountered the following error: Could not find rake-13.0.6 in any of the sources (Bundler::GemNotFound)
App 29384 output: /opt/ruby-2.5/lib64/ruby/gems/2.5.0/gems/bundler-1.17.3/lib/bundler/spec_set.rb:91:in `block in materialize'
...

I note that Bundler is looking for a Gem in /opt/ruby-2.5, however the app’s ./.ruby-version is set to 2.7.4.

My hunch is that the Passenger configuration is set to an old version of Ruby, which has missing dependencies. In a way the missing deps error is lucky, because otherwise the app would be running on an outdated Ruby version compared to dev.

To validate my theory, I check the Passenger config for my app.

➜ ssh [email protected]
➜ sudo su
➜ ls /etc/httpd/conf.d/vhost
...
my-app-name-int.conf my-app-name-uat.conf
...

After identifying the correct config file, I check the contents. Sure enough, the Ruby version is set incorrectly to 2.5:

➜ cat /etc/httpd/conf.d/vhost/my-app-name-uat.conf
...
PassengerRuby /opt/ruby-2.5/bin/ruby
...

I backup the config file, then update the Ruby version to be correct:

➜ cp /etc/httpd/conf.d/vhost/my-app-name-uat.conf /etc/httpd/conf.d/vhost/my-app-name-uat.conf.bak # backup the current configuration
➜ vim /etc/httpd/conf.d/vhost/my-app-name-uat.conf # edit the current config
...
# PassengerRuby /opt/ruby-2.5/bin/ruby
PassengerRuby /opt/ruby-2.7/bin/ruby
...
➜ service httpd reload # reload Apache to apply the changes

# ➜ apachectl restart # if Apache issues encountered, restart Apache

Note: if PassengerRuby is already correct here, the Ruby version might still be missing gems – continue to the next steps

Finally, I manually install the missing Ruby deps. Note: these commands are run using the appropriate app service account, not root.

➜ cd /var/www/my-app-name-uat/current
➜ export PATH=/opt/ruby-2.7/bin:$PATH
➜ bundle install

Passenger now successfully launches my app when the url is visited in a web browser.

Note that this complete update process must be done on each server node if using a load balanced group.

If further bundler errors are encountered, the system gems might need to be updated:

PATH=/opt/ruby-2.7/bin:$PATH gem update --system

Note: make sure to to include the –system flag here, otherwise other apps on the server might be impacted.

Full Error Trace

➜ tail -f /etc/httpd/logs/error_log

App 29384 output: [passenger_native_support.so] not found for current Ruby interpreter.
App 29384 output: This library provides various optimized routines that make
App 29384 output: Phusion Passenger faster. Please run 'sudo yum install passenger-devel-6.0.7'
App 29384 output: so that Phusion Passenger can compile one on the next run.
App 29384 output: [passenger_native_support.so] not downloading because PASSENGER_DOWNLOAD_NATIVE_SUPPORT_BINARY=0
App 29384 output: [passenger_native_support.so] will not be used (can't compile or download)
App 29384 output: --> Passenger will still operate normally.
App 29384 output: Error: The application encountered the following error: Could not find rake-13.0.6 in any of the sources (Bundler::GemNotFound)
App 29384 output: /opt/ruby-2.5/lib64/ruby/gems/2.5.0/gems/bundler-1.17.3/lib/bundler/spec_set.rb:91:in block in materialize' App 29384 output: /opt/ruby-2.5/lib64/ruby/gems/2.5.0/gems/bundler-1.17.3/lib/bundler/spec_set.rb:85:inmap!'
App 29384 output: /opt/ruby-2.5/lib64/ruby/gems/2.5.0/gems/bundler-1.17.3/lib/bundler/spec_set.rb:85:in materialize' App 29384 output: /opt/ruby-2.5/lib64/ruby/gems/2.5.0/gems/bundler-1.17.3/lib/bundler/definition.rb:170:inspecs'
App 29384 output: /opt/ruby-2.5/lib64/ruby/gems/2.5.0/gems/bundler-1.17.3/lib/bundler/definition.rb:237:in specs_for' App 29384 output: /opt/ruby-2.5/lib64/ruby/gems/2.5.0/gems/bundler-1.17.3/lib/bundler/definition.rb:226:inrequested_specs'
App 29384 output: /opt/ruby-2.5/lib64/ruby/gems/2.5.0/gems/bundler-1.17.3/lib/bundler/runtime.rb:108:in block in definition_method' App 29384 output: /opt/ruby-2.5/lib64/ruby/gems/2.5.0/gems/bundler-1.17.3/lib/bundler/runtime.rb:20:insetup'
App 29384 output: /opt/ruby-2.5/lib64/ruby/gems/2.5.0/gems/bundler-1.17.3/lib/bundler.rb:107:in setup' App 29384 output: /opt/ruby-2.5/lib64/ruby/gems/2.5.0/gems/bundler-1.17.3/lib/bundler/setup.rb:20:in'
App 29384 output: /opt/ruby-2.5/lib64/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in require' App 29384 output: /opt/ruby-2.5/lib64/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:inrequire'
App 29384 output: /usr/share/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:365:in activate_gem' App 29384 output: /usr/share/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:221:inblock in run_load_path_setup_code'
App 29384 output: /usr/share/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:529:in running_bundler' App 29384 output: /usr/share/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:220:inrun_load_path_setup_code'
App 29384 output: /usr/share/passenger/helper-scripts/rack-preloader.rb:91:in preload_app' App 29384 output: /usr/share/passenger/helper-scripts/rack-preloader.rb:189:inblock in '
App 29384 output: /usr/share/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:382:in run_block_and_record_step_progress' App 29384 output: /usr/share/passenger/helper-scripts/rack-preloader.rb:188:in'
App 29384 output: /usr/share/passenger/helper-scripts/rack-preloader.rb:30:in <module:PhusionPassenger>' App 29384 output: /usr/share/passenger/helper-scripts/rack-preloader.rb:29:in'
[ E 2022-08-02 17:37:44.7235 2524/T8h age/Cor/App/Implementation.cpp:221 ]: Could not spawn process for application /var/www/my-app-name/current: The application encountered the following error: Could not find rake-13.0.6 in any of the sources (Bundler::GemNotFound)
Error ID: 60047415
Error details saved to: /tmp/passenger-error-DEwgnV.html

[ E 2022-08-02 17:37:44.7526 2524/Te age/Cor/Con/CheckoutSession.cpp:276 ]: [Client 4-2281] Cannot checkout session because a spawning error occurred. The identifier of the error is 60047415. Please see earlier logs for details about the error.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s