[rubygems] cannot load such file -- bundler/setup (LoadError)

I'm setting Rails 4 application with Ruby 2.0, but I'm getting "Web application could not be started" and get this trace:

cannot load such file -- bundler/setup (LoadError)
  /usr/local/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:53:in `require'
  /usr/local/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:53:in `require'
  /usr/lib/ruby/gems/1.8/gems/passenger-4.0.19/lib/phusion_passenger/loader_shared_helpers.rb:212:in `run_load_path_setup_code'
  /usr/lib/ruby/gems/1.8/gems/passenger-4.0.19/helper-scripts/rack-preloader.rb:96:in `preload_app'
  /usr/lib/ruby/gems/1.8/gems/passenger-4.0.19/helper-scripts/rack-preloader.rb:150:in `<module:App>'
  /usr/lib/ruby/gems/1.8/gems/passenger-4.0.19/helper-scripts/rack-preloader.rb:29:in `<module:PhusionPassenger>'
  /usr/lib/ruby/gems/1.8/gems/passenger-4.0.19/helper-scripts/rack-preloader.rb:28:in `<main>'

My apache2.conf is:

LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-4.0.19/buildout/apache2/mod_passenger.so
   PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-4.0.19
   PassengerDefaultRuby /usr/local/bin/ruby

bundle -v is:

Bundler version 1.3.5

ruby -v is:

ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]

gem env is:

RubyGems Environment:
  - RUBYGEMS VERSION: 2.1.5
  - RUBY VERSION: 2.0.0 (2013-06-27 patchlevel 247) [x86_64-linux]
  - INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8
  - RUBY EXECUTABLE: /usr/local/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/lib/ruby/gems/1.8/bin
  - SPEC CACHE DIRECTORY: /root/.gem/specs
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /usr/lib/ruby/gems/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /root/.gems/bin
     - /usr/lib/ruby/gems/1.8/bin/
     - /usr/local/bin
     - /usr/bin
     - /bin
     - /usr/bin/X11
     - /usr/games
     - /usr/sbin
     - /sbin

echo $GEM_PATH is:

/usr/lib/ruby/gems/1.8:/usr/lib/ruby/gems/1.8

Shouldn't GEM_PATH be /usr/lib/ruby/gems/2.0?

Inside the virtual host in apache2.conf I added:

SetEnv GEM_HOME /usr/lib/ruby/gems/1.8

And now it is working.

Is it the right way to fix this?

This question is related to rubygems ruby-on-rails-4 passenger ruby-2.0

The answer is


Other possible situation: you have multiple users defined in your server environment. In that case, running

passenger-config --ruby-command

will give you the necessary command to specify your nginx/sites-enabled/relevant_application file with your use case, example:

passenger-config was invoked through the following Ruby interpreter:
Command: /home/other_user/.rbenv/versions/2.4.5/bin/ruby
Version: ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-linux]
To use in Apache: PassengerRuby /home/other_user/.rbenv/versions/2.4.5/bin/ruby
To use in Nginx : passenger_ruby /home/other_user/.rbenv/versions/2.4.5/bin/ruby
To use with Standalone: /home/other_user/.rbenv/versions/2.4.5/bin/ruby /usr/bin/passenger start

NOTE: My hosting company is Site5.com and I have a Managed VPS.

I added env variables for both GEM_HOME and GEM_PATH to the .htaccess file in my public_html directory (an alias to the public directory in the rails app)

They were not needed before so something must have changed on the hosts side. It got this error after touching the restart.txt file to restart the passenger server.

Got GEM_PATH by:

echo $GEM_PATH

Got the GEM_HOME by:

gem env

 RubyGems Environment:
   - RUBYGEMS VERSION: 2.0.14
   - RUBY VERSION: 2.0.0 (2013-11-22 patchlevel 353) [x86_64-linux]
   - INSTALLATION DIRECTORY: /home/username/ruby/gems
   - RUBY EXECUTABLE: /usr/local/ruby20/bin/ruby
   - EXECUTABLE DIRECTORY: /home/username/ruby/gems/bin
   - RUBYGEMS PLATFORMS:
     - ruby
     - x86_64-linux
   - GEM PATHS:
      - /home/username/ruby/gems
      - /usr/local/ruby2.0/lib64/ruby/gems/
   - GEM CONFIGURATION:
      - :update_sources => true
      - :verbose => true
      - :backtrace => false
      - :bulk_threshold => 1000
      - "gem" => "--remote --gen-rdoc --run-tests"
      **- "gemhome" => "/home/username/ruby/gems"**
      - "gempath" => ["/home/username/ruby/gems", "/usr/local/ruby2.0/lib64/ruby/gems/"]
      - "rdoc" => "--inline-source --line-numbers"
   - REMOTE SOURCES:
      - https://rubygems.org/

Updated .htaccess file with the following lines:

SetEnv GEM_HOME /usr/local/ruby2.0/lib64/ruby/gems/
SetEnv GEM_PATH /home/username/ruby/gems:/usr/local/ruby20/lib64/ruby/gems/:/home/username/ruby/gems:/usr/

I had almost precisely the same error, and was able to completely fix it simply by running:

gem install bundler

It's possible your bundler installation is corrupt or missing - that's what happened in my case. Note that if the above fails you can try:

sudo gem install bundler

...but generally you can do it without sudo.


In my situation it was matter of the permissions:

 sudo chmod -R +777 <your_folder_path>

In my case, the lines appended to the apache config file after installing passenger were as follows:

LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-.0.24/buildout/apache2/mod_passenger.so 
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-4.0.24 
PassengerDefaultRuby /usr/bin/ruby1.8

But the app requires Ruby 2.0.0 so it took me a while but finally, the error was resolved after specifying a different path using 'PassengerRuby' below, within the Apache virtual host config file for the app:

...
VirtualHost *:80>
  ServerName www.yourhost.com

 **PassengerRuby /home/user/.rvm/gems/ruby-2.0.0-p247**
  # !!! Be sure to point DocumentRoot to 'public'!
  DocumentRoot /somewhere/public    
  <Directory /somewhere/public>
     # This relaxes Apache security settings.
     AllowOverride all
     # MultiViews must be turned off.
     Options -MultiViews
  </Directory>
</VirtualHost...

I ran into the same issue, but I think it was due to spring caching some gems and configurations. I fixed it by running gem pristine --all.

This restores installed gems to pristine condition from files located in the gem cache.

or you can just try for your gem like

gem pristine your_gem_name

I got this error in a fresh Rails app with bundle correctly installed. Commenting out the spring gem in Gemfile resolved the problem.


i had the same issue and tried all the answers without any luck.

steps i did to reproduce:

  1. rvm instal 2.1.10
  2. rvm gemset create my_gemset
  3. rvm use 2.1.10@my_gemset
  4. bundle install

however bundle install installed Rails, but i still got cannot load such file -- bundler/setup (LoadError)

finally running gem install rails -v 4.2 fixed it


For me the problem was associating RVM Ruby with Passenger. So I needed to integrate RVM ruby wrapper to passenger config file.

I find out rvm ruby wrapper path with command:

passenger-config --ruby-command

I took the path from the result and entered to a passenger config in nginx/passenger.conf:

passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /usr/local/rvm/gems/ruby-2.3.1/wrappers/ruby;

This was happening in the production environment for me.

rm /vendor/bundle

then bundle install --deployment

resolved the issue.


I've fixed that problem by creating test rails project and install all gems then I've replaced my current Gemfile.lock with the test and all thing works fine.

I think that this problem from bundler versions with hosting, so please make sure that hosting bundler is the same version with your project.


I had this because something bad was in my vendor/bundle. Nothing to do with Apache, just in local dev env.

To fix, I deleted vendor\bundle, and also deleted the reference to it in my .bundle/config so it wouldn't get re-used.

Then, I re-bundled (which then installed to GEM_HOME instead of vendor/bundle and the problem went away.


You can try to run:

bundle exec rake rails:update:bin

As @Dinesh mentioned in Rails 5:

rails app:update:bin

After spend a lot time, trying follow these answers actually after code below it worked for me. Before do it just but be sure that there is no problem in update :)

gem update --system


The version of ruby version which phusion passenger was used is differenced with your rails app.

<IfModule mod_passenger.c>
  PassengerRoot /usr/local/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/passenger-6.0.2
  PassengerDefaultRuby /usr/local/rbenv/versions/2.5.3/bin/ruby
</IfModule>

Make sure the version on httpd config is the same with rails app.


You most likely have more than one Ruby installed.

If you are using RVM, you probably need to run:

rvm use system

to set the version of ruby to use.

See http://rvm.io/rubies/default

ruby -v

will tell you the version you are currently using.


Bundler Version maybe cause the issue.

Please install bundler with other version number.

For example,

gem install bundler -v 1.0.10


Examples related to rubygems

You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory. (mac user) find_spec_for_exe': can't find gem bundler (>= 0.a) (Gem::GemNotFoundException) How to fix "Your Ruby version is 2.3.0, but your Gemfile specified 2.2.5" while server starting You don't have write permissions for the /var/lib/gems/2.3.0 directory Can't install gems on OS X "El Capitan" How to avoid "cannot load such file -- utils/popen" from homebrew on OSX How can I set a proxy server for gem? How to install CocoaPods? Error while installing json gem 'mkmf.rb can't find header files for ruby' How to downgrade or install an older version of Cocoapods

Examples related to ruby-on-rails-4

Uninitialized Constant MessagesController Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? NameError: uninitialized constant (rails) How to solve error "Missing `secret_key_base` for 'production' environment" (Rails 4.1) ActionController::UnknownFormat Add a reference column migration in Rails 4 PG::ConnectionBad - could not connect to server: Connection refused Auto-loading lib files in Rails 4 cannot load such file -- bundler/setup (LoadError) Rails 4: how to use $(document).ready() with turbo-links

Examples related to passenger

cannot load such file -- bundler/setup (LoadError)

Examples related to ruby-2.0

cannot load such file -- bundler/setup (LoadError)