cannot load such file -- bundler/setup (LoadError)
Asked Answered
T

18

151

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?

Thorner answered 27/9, 2013 at 23:57 Comment(0)
L
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:

Lovejoy answered 30/9, 2013 at 17:0 Comment(0)
M
234

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.

Most answered 3/1, 2016 at 10:56 Comment(7)
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.Statutable
In my case, yes, but I think it depends on your operating system. I initially did it on a Linux Mint 17, but on an OSX box sudo may not have been necessary. Also, I'd already installed all of my other Ruby-related software using sudo. (Bad practice, but it's not for production-facing applications at this point anyway).Most
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.Bipack
Update: you don't generally need sudo for this on OSX. I second what @Bipack says. As a general note: only ever use sudo as a last resort for anything to do with Ruby (I've updated my answer to reflect this)Most
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.Electrodynamic
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.Cilurzo
Hi, I have the same problem as the question using ubuntu with gem 2.7.6 and ruby 2.5.0p0 what to do?Verduzco
L
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:

Lovejoy answered 30/9, 2013 at 17:0 Comment(0)
P
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.

Pussy answered 10/10, 2013 at 17:38 Comment(0)
S
28

You can try to run:

bundle exec rake rails:update:bin

As @Dinesh mentioned in Rails 5:

rails app:update:bin
Scheller answered 18/4, 2016 at 18:58 Comment(0)
C
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...
Crisscross answered 15/11, 2013 at 22:0 Comment(1)
This was the case with me as well. In my case PassengerDefaultRuby was referring to an old installation of ruby.Registrar
B
8

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

Bibliolatry answered 21/2, 2015 at 6:44 Comment(1)
This was it for me but gem install spring instead of commenting out.Adulteress
C
7

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
Cribble answered 11/6, 2018 at 12:4 Comment(0)
P
7

Bundler Version maybe cause the issue.

Please install bundler with other version number.

For example,

gem install bundler -v 1.0.10

Psaltery answered 25/1, 2019 at 3:25 Comment(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'.Pavyer
T
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

Tape answered 7/8, 2020 at 18:12 Comment(1)
you're the best!Unreasonable
H
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
Harmsworth answered 9/1, 2019 at 14:40 Comment(0)
H
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;
Horse answered 25/3, 2017 at 14:28 Comment(0)
A
1

This was happening in the production environment for me.

rm /vendor/bundle

then bundle install --deployment

resolved the issue.

Ass answered 7/11, 2018 at 22:1 Comment(0)
A
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.

Andizhan answered 15/6, 2019 at 18:26 Comment(0)
Y
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.

Yeoman answered 25/2, 2016 at 5:39 Comment(0)
M
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/
Megrim answered 16/2, 2017 at 3:30 Comment(0)
H
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

Hawkeyed answered 21/1, 2019 at 13:18 Comment(0)
A
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.

Aponte answered 18/11, 2019 at 16:55 Comment(0)
J
-1

In my situation it was matter of the permissions:

 sudo chmod -R +777 <your_folder_path>
Jarrodjarrow answered 27/8, 2019 at 14:8 Comment(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.Schoof

© 2022 - 2024 — McMap. All rights reserved.