cannot load such file -- bundler/setup (LoadError)
Solution 1
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:
- New to Ruby and am having trouble with LOAD_PATH
- http://weblog.rubyonrails.org/2009/9/1/gem-packaging-best-practices/
- http://guides.rubygems.org/faqs/
Solution 2
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 3
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
You can try to run:
bundle exec rake rails:update:bin
As @Dinesh mentioned in Rails 5:
rails app:update:bin
Solution 5
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...
Mr_Nizzle
Software Developer (Web and iOS) Skills: Ruby on Rails iOS Development (Objective-C, Switf) Developer at Applaudo Studios http://http://applaudostudios.com
Updated on August 08, 2020Comments
-
Mr_Nizzle over 3 years
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?
-
jakenberg over 8 yearsThis was it for me but
gem install spring
instead of commenting out. -
Pete over 8 yearsThis was me! Question--is the
sudo
actually neccessary? I usedsudo
but now I'm wondering what would have happened if I hadn't. -
Andrew Faulkner about 8 yearsIn 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).
-
Farfromunique almost 8 yearsIf you're using a different version of Ruby than the system default, you need to NOT use
sudo
!sudo gem ....
will install thedefault
version of the gem, and (in my case, Ubuntu 14.04)sudo
can't run rvm. -
Andrew Faulkner over 7 yearsUpdate: you don't generally need sudo for this on OSX. I second what @Farfromunique 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)
-
Waseem over 7 yearsThis was the case with me as well. In my case
PassengerDefaultRuby
was referring to an old installation of ruby. -
Ben Visness almost 7 yearsOn 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. -
evanlivingston over 6 yearsJust 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.
-
TheCrazyProfessor about 6 yearsHi, I have the same problem as the question using ubuntu with
gem 2.7.6
andruby 2.5.0p0
what to do? -
SergA over 4 yearsIn my case this error occurs after installing bundler v2. I resolve it with
gem uninstall -a bundler; gem install bundler -v '<2.0'
. -
Florian Doyen almost 4 years-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.
-
brauliobo almost 3 yearsyou're the best!