cannot load such file -- bundler/setup (LoadError)
RubygemsRuby on-Rails-4PassengerRuby 2.0Rubygems Problem Overview
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?
Rubygems Solutions
Solution 1 - Rubygems
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.
Solution 2 - Rubygems
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:
Solution 3 - Rubygems
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.
Solution 4 - Rubygems
You can try to run:
bundle exec rake rails:update:bin
As @Dinesh mentioned in Rails 5:
rails app:update:bin
Solution 5 - Rubygems
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...
Solution 6 - Rubygems
I got this error in a fresh Rails app with bundle correctly installed. Commenting out the spring gem in Gemfile resolved the problem.
Solution 7 - Rubygems
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
Solution 8 - Rubygems
Bundler Version maybe cause the issue.
Please install bundler with other version number.
For example,
gem install bundler -v 1.0.10
Solution 9 - Rubygems
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
Solution 10 - Rubygems
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
Solution 11 - Rubygems
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;
Solution 12 - Rubygems
This was happening in the production environment for me.
rm /vendor/bundle
then
bundle install --deployment
resolved the issue.
Solution 13 - Rubygems
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.
Solution 14 - Rubygems
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/
Solution 15 - Rubygems
i had the same issue and tried all the answers without any luck.
steps i did to reproduce:
rvm instal 2.1.10
rvm gemset create my_gemset
rvm use 2.1.10@my_gemset
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
Solution 16 - Rubygems
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.
Solution 17 - Rubygems
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.
Solution 18 - Rubygems
In my situation it was matter of the permissions:
sudo chmod -R +777 <your_folder_path>