152

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?

20 Answers 20

238

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.

7
  • 3
    This was me! Question--is the sudo actually neccessary? I used sudo but now I'm wondering what would have happened if I hadn't.
    – Pete
    Commented Jan 21, 2016 at 20:30
  • 2
    If you're using a different version of Ruby than the system default, you need to NOT use sudo! sudo gem .... will install the default version of the gem, and (in my case, Ubuntu 14.04) sudo can't run rvm. Commented Jun 1, 2016 at 23:46
  • 1
    On my macOS system, I needed sudo for the system default ruby, but didn't need it for any version of ruby I installed with rvm. Commented Jun 13, 2017 at 15:00
  • 1
    Just a note to say that this was the solution for me using Windows Subsystem for Linux, after the recent Windows update. For some reason the update blew away my RVM ruby installs.
    – Ben Fulton
    Commented Nov 7, 2017 at 16:32
  • 1
    Hi, I have the same problem as the question using ubuntu with gem 2.7.6 and ruby 2.5.0p0 what to do? Commented Apr 13, 2018 at 7:12
50

It could be that there was a previous Ruby env installed on your system prior to your installation of 2.0? This might have had an existing GEM_PATH that lead to the /1.8 directory which the installation of version 2.0 simply kept.

The problem you where likely having, then, was that Passenger/Apache was looking in the /2.0 directory when in fact the gems were in the /1.8 directory. Your explicitly telling apache to use the /1.8 directory thus makes sense to fix the problem.

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

You might also try using the Ruby Version Manager to handle multiple Ruby envs.

Some things I found in Google:

31

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.

28

You can try to run:

bundle exec rake rails:update:bin

As @Dinesh mentioned in Rails 5:

rails app:update:bin
0
10

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...
1
  • This was the case with me as well. In my case PassengerDefaultRuby was referring to an old installation of ruby.
    – Waseem
    Commented Sep 9, 2016 at 15:14
8

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

1
  • 4
    This was it for me but gem install spring instead of commenting out.
    – jakenberg
    Commented Nov 30, 2015 at 4:06
8

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
7

Bundler Version maybe cause the issue.

Please install bundler with other version number.

For example,

gem install bundler -v 1.0.10

1
  • 1
    In my case this error occurs after installing bundler v2. I resolve it with gem uninstall -a bundler; gem install bundler -v '<2.0'.
    – SergA
    Commented Jan 23, 2020 at 10:02
5

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

1
  • you're the best!
    – brauliobo
    Commented Apr 28, 2021 at 10:39
2

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
1

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;
1

This was happening in the production environment for me.

rm /vendor/bundle

then bundle install --deployment

resolved the issue.

1

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.

0

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.

0

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/
0

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

0

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.

0

I just wanted to offer that I had some weird permissions issues with ruby installed via homebrew. I didn't have write access to some gem dirs. I'm not sure why. I work at a bank so maybe some software on this mac caused the write access problems but after I did a:

chmod +w /opt/homebrew

and then a

gem install bundler

bundler started working

0

huh..I updated my bundler version and this issue got resolved. Command to do so:

bundle update --bundler
-1

In my situation it was matter of the permissions:

 sudo chmod -R +777 <your_folder_path>
1
  • 1
    -1 : Never put 777 on files or directories. If there is a split between "owner", "group" and "others", it's because it's a security matter. Commented Jun 6, 2020 at 15:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.