bundle install not working in my project ruby on rails - ruby-on-rails

I don't know what I missed in my setup. I used rbenv for installing ruby. I learn it this page link. I successfully install ruby and rails. But the problem I have now is when I am in my current project. I did try this command inside my project bundle install, but I always get this error
Traceback (most recent call last):
2: from /home/user90/.rbenv/versions/2.5.1/bin/bundle:23:in `<main>'
1: from /home/user90/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems.rb:308:in `activate_bin_path'
/home/user90/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems.rb:289:in `find_spec_for_exe': can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)
same as doing this command in my current project rails -v
Traceback (most recent call last):
4: from bin/rails:5:in `<main>'
3: from bin/rails:5:in `load'
2: from /var/www/automated-leave-app/bin/spring:9:in `<top (required)>'
1: from /home/user90/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/home/user90/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- bundler (LoadError)
I also install gem install bundler in my current setup. Does the version matters? Here are my current setup version.
rails 5.2.0
ruby 2.5.1
gem 2.7.6

Solutions for 'Cant find gem bundler (>= 0.a) with executable bundle'
This is official doc on this error, you should have found this on top if you googled correctly. Gist is that there is bundler version mismatch, check gemfile.lock for bundler version and than install that version of bundler.
gem install bundler -v VERSION_FROM_GEMFILE
for example
gem install bundler -v 1.17

Related

Rails upgrade is complaining about older bundler version

I want to upgrade from Rails 4.2 to 6. I have updated my Gemfile to include
fail "run 'gem install bundler' to update your bundler version" unless Bundler::VERSION >= '2.0.0'
source 'https://rubygems.org'
ruby '~> 2.7.1'
gem 'rails', '~> 6.0.0'
But attempting to upgrade the rails gem results in
$ bundle update rails
Traceback (most recent call last):
4: from /Users/myusername/.rvm/gems/ruby-2.7.1/bin/ruby_executable_hooks:22:in `<main>'
3: from /Users/myusername/.rvm/gems/ruby-2.7.1/bin/ruby_executable_hooks:22:in `eval'
2: from /Users/myusername/.rvm/gems/ruby-2.7.1/bin/bundle:23:in `<main>'
1: from /Users/myusername/.rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0/rubygems.rb:294:in `activate_bin_path'
/Users/myusername/.rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0/rubygems.rb:275:in `find_spec_for_exe': Could not find 'bundler' (1.17.3) required by your /Users/myusername/myrailsapp/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:1.17.3`
When I try and update the bundler, I get
$ bundle update --bundler
Fetching https://github.com/mimemagicrb/mimemagic.git
Fetching gem metadata from https://rubygems.org/.......
You have requested:
rails ~> 6.0.0
The bundle currently has rails locked at 4.2.10.
Try running `bundle update rails`
If you are updating multiple gems in your Gemfile at once,
try passing them all to `bundle update`
And as you might expect, running “bundle update” also results in an error …
$ bundle update
Traceback (most recent call last):
4: from /Users/myusername/.rvm/gems/ruby-2.7.1/bin/ruby_executable_hooks:22:in `<main>'
3: from /Users/myusername/.rvm/gems/ruby-2.7.1/bin/ruby_executable_hooks:22:in `eval'
2: from /Users/myusername/.rvm/gems/ruby-2.7.1/bin/bundle:23:in `<main>'
1: from /Users/myusername/.rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0/rubygems.rb:294:in `activate_bin_path'
/Users/myusername/.rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0/rubygems.rb:275:in `find_spec_for_exe': Could not find 'bundler' (1.17.3) required by your /Users/myusername/myrailsapp/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:1.17.3`
Not sure where else to go from here.

How to solve bundler LoadError

I am using rvm and running Ruby 2.6.1 and using rails 5.2.2. When I try bundler -v
I get the error:
Traceback (most recent call last):
3: from /home/amairu/.rvm/gems/ruby-2.6.1#rails522/bin/ruby_executable_hooks:24:in `<main>'
2: from /home/amairu/.rvm/gems/ruby-2.6.1#rails522/bin/ruby_executable_hooks:24:in `eval'
1: from /home/amairu/.rvm/gems/ruby-2.6.1#rails522/bin/bundler:23:in `<main>'
/home/amairu/.rvm/gems/ruby-2.6.1#rails522/bin/bundler:23:in `load': cannot load such file -- /home/amairu/.rvm/rubies/ruby-2.6.1/lib/ruby/gems/2.6.0/gems/bundler-1.17.3/exe/bundler (LoadError)
gem list bundler returns:
*** LOCAL GEMS ***
bundler (2.0.2, default: 1.17.3, 1.17.2)
bundler-unload (1.0.2)
rubygems-bundler (1.4.5)
It seems that it is trying to look for the file named "bundler" in /home/amairu/.rvm/rubies/ruby-2.6.1/lib/ruby/gems/2.6.0/gems/bundler-1.17.3/exe/ folder but there is no such file. The required file is in a different folder:
ls /home/amairu/.rvm/rubies/ruby-2.6.1/lib/ruby/gems/2.6.0/gems/bundler-1.17.2/exe/
> bundler
How can I set it such that the bundler -v command looks into the bundler-1.17.2/exe instead of the bundler-1.17.3/exe? In other words I need to set the default bundler version as 1.17.2 instead of 1.17.3
I have run:
gem uninstall bundler
gem install bundler
bundle install
Which install successfully but still I get an error with bundler -v.
A similar post suggest reinstalling Rails gem install rails -v 5.2.2 but this did not fix my issue.
You can try by uninstalling the bundler with version
gem uninstall bundler -v 2.0.2
gem uninstall bundler -v 1.17.3
gem uninstall bundler -v 1.17.2
and then check the gem list that bundler has been uninstalled
gem list bundler
If its get uninstalled then you can install bundler with version again
gem install bundler -v 1.17.2
Or if its not uninstalled then might be bundler gem is in your default gemset so you can use the default gemset and then try uninstalling and then install 1.17.2 again
rvm gemset use default
gem uninstall bundler -v 2.0.2
gem uninstall bundler -v 1.17.3
gem uninstall bundler -v 1.17.2
gem install bundler -v 1.17.2
I know this is quite old, but just to help anyone that is facing the same problem:
/home/amairu/.rvm/gems/ruby-2.6.1#rails522/bin/bundler:23:in `load': cannot load such file -- /home/amairu/.rvm/rubies/ruby-2.6.1/lib/ruby/gems/2.6.0/gems/bundler-1.17.3/exe/bundler (LoadError)
You have to reinstall the exact version that ruby is complying. In the error message above, it was looking for bundler version 1.17.3.
So you should only reinstall this exact version.
gem install bundler -v 1.17.3

Can not downgrade bundler

I am getting this error while trying to push my app to heroku:
Warning: the running version of Bundler (1.17.2) is older than the version that created the lockfile (1.17.3). We suggest you upgrade to the latest version of Bundler by runninggem install bundler. I have the following versions of bundler:
gem list | grep bundler
bundler (2.0.2, default: 1.17.3, 1.17.2)
I have tried various suggestions from different similar posts but I am not able to set the bundler version to 1.17.2 which is required by Heroku. I tried:
gem uninstall bundler
gem install bundler -v 1.17.2
1 gem installed
Then removed the lock file and rerunning the bundle update but the version 1.17.3 still comes as the default.
I tried gem uninstall bundler:1.17.3 which returned:
Successfully uninstalled bundler-1.17.3
Then: gem install bundler -v 1.17.2which returned:
Successfully installed bundler-1.17.2
1 gem installed
Now bundler -v returns a LoadError:
Traceback (most recent call last):
3: from /home/amairu/.rvm/gems/ruby-2.6.1#rails522/bin/ruby_executable_hooks:24:in `<main>'
2: from /home/amairu/.rvm/gems/ruby-2.6.1#rails522/bin/ruby_executable_hooks:24:in `eval'
1: from /home/amairu/.rvm/gems/ruby-2.6.1#rails522/bin/bundler:23:in `<main>'
/home/amairu/.rvm/gems/ruby-2.6.1#rails522/bin/bundler:23:in `load': cannot load such file -- /home/amairu/.rvm/rubies/ruby-2.6.1/lib/ruby/gems/2.6.0/gems/bundler-1.17.3/exe/bundler (LoadError)
I am using rvm and I also tried to uninstall in the global gem set:
rvm use 2.6.1#global
gem uninstall bundler:1.17.3 which does not return any output or message.
How can I set the bundler to 1.17.2?
set your bundler version as a default version like below if you want to use 2.0.2
bundle _2.0.2_ -v
I had troubles with bundlers recently (Bundler v2.0.2 was installed, v1.17.3 set as default) but with a different error (Can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)).
Running gem update --system did a trick for me.
Install the correct bundler for your application with the following command:
gem install bundler -v "$(grep -A 1 "BUNDLED WITH" Gemfile.lock | tail -n 1)"

How to fix Could not find 'activesupport' (= 6.0.0.rc1) - did find: [activesupport-5.2.3] (Gem::MissingSpecVersionError)

I tried installing Rails 6 rc1 on my machine. I then remove each Active* or Action* gems. And I'm encountering this error.
I have tried to do a bundle update but to no avail. I am using rbenv.
Can anyone give me a pointer? Thank you!
➜ Desktop git:(master) ✗ rails
Traceback (most recent call last):
8: from /Users/xxxx/.rbenv/versions/2.6.3/bin/rails:23:in `<main>'
7: from /Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems.rb:303:in `activate_bin_path'
6: from /Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems.rb:303:in `synchronize'
5: from /Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems.rb:304:in `block in activate_bin_path'
4: from /Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/specification.rb:1420:in `activate'
3: from /Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/specification.rb:1438:in `activate_dependencies'
2: from /Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/specification.rb:1438:in `each'
1: from /Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/specification.rb:1449:in `block in activate_dependencies'
/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/dependency.rb:313:in `to_specs': Could not find 'activesupport' (= 6.0.0.rc1) - did find: [activesupport-5.2.3] (Gem::MissingSpecVersionError)
Checked in 'GEM_PATH=/Users/xxxx/.gem/ruby/2.6.0:/Users/xxxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0', execute `gem env` for more information
After testing it out, I realise that railties is the main culprit.
I also made a mistake of uninstall rails the wrong way. Please refer below to find the correct way to uninstall rails rc.
So i simply reinstall rails to fix the error above. Then I uninstall it again. Then I uninstall railties
gem install rails --pre
gem uninstall rails -v 6.0.0.rc1
gem uninstall railsties -v 6.0.0.rc1

Ruby on rails bundle install - json error

I have a lot of difficulties to run Ruby on Rails. Maybe you can tell me where I'm wrong ?
I'm on Linux Mint 17.2, with LAMP local server.
To install Ruby :
$ sudo apt-get install ruby
$ ruby -v
ruby 1.9.3p484
$
I didn't have to install gem, it works as shown here :
$ gem help commands
GEM commands are:
build Build a gem from a gemspec
cert Manage RubyGems certificates and signing settings
(...)
update Update the named gems (or all installed gems) in the local
repository
which Find the location of a library file you can require
For help on a particular command, use 'gem help COMMAND'.
Commands may be abbreviated, so long as they are unambiguous.
e.g. 'gem i rake' is short for 'gem install rake'.
Then I installed rails, I dont remember which of those two ways :
$ sudo gem install rails
or
$ sudo apt-get install ruby-railties-4.0
I dont find how to uninstall, so I can't test other ways to install.
Then, I made an application :
$ rails new (path)/second_app
create
create README.rdoc
create Rakefile
create config.ru
create .gitignore
create Gemfile
create app
create app/assets/javascripts/application.js
(...)
create vendor/assets/javascripts
create vendor/assets/javascripts/.keep
create vendor/assets/stylesheets
create vendor/assets/stylesheets/.keep
run bundle install
/usr/lib/ruby/1.9.1/rubygems.rb:308:in `bin_path': can't find gem bundler (>= 0) (Gem::GemNotFoundException)
from /var/lib/gems/1.9.1/gems/railties-4.0.2/lib/rails/generators/app_base.rb:268:in `bundle_command'
from /var/lib/gems/1.9.1/gems/railties-4.0.2/lib/rails/generators/app_base.rb:277:in `run_bundle'
from (eval):1:in `run_bundle'
from /var/lib/gems/1.9.1/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
from /var/lib/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
from /var/lib/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `block in invoke_all'
from /var/lib/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `each'
from /var/lib/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `map'
from /var/lib/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `invoke_all'
from /var/lib/gems/1.9.1/gems/thor-0.19.1/lib/thor/group.rb:232:in `dispatch'
from /var/lib/gems/1.9.1/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
from /var/lib/gems/1.9.1/gems/railties-4.0.2/lib/rails/commands/application.rb:43:in `<top (required)>'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /var/lib/gems/1.9.1/gems/railties-4.0.2/lib/rails/cli.rb:15:in `<top (required)>'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /var/lib/gems/1.9.1/gems/railties-4.0.2/bin/rails:9:in `<top (required)>'
from /usr/local/bin/rails:23:in `load'
from /usr/local/bin/rails:23:in `<main>'
It looks like it was a problem running bundle install. According to tutorials, I run the command
$ bundle install
And I got
Fetching gem metadata from https://rubygems.org/............
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies...
Using rake (10.4.2)
Using i18n (0.7.0)
Using minitest (4.7.5)
…
Using jbuilder (1.5.3)
Using jquery-rails (3.1.3)
Installing json (1.8.3)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from extconf.rb:1:in `<main>'
Gem files will remain installed in /home/alejandro/.bundler/tmp/9377/gems/json-1.8.3 for inspection.
Results logged to /home/alejandro/.bundler/tmp/9377/gems/json-1.8.3/ext/json/ext/generator/gem_make.out
An error occurred while installing json (1.8.3), and Bundler cannot continue.
Make sure that `gem install json -v '1.8.3'` succeeds before bundling.
I tryed to install json in several ways :
$ sudo gem install json -v '1.8.3'
$ sudo apt-get install json -v '1.8.3'
$ sudo gem install json
But it don't work. I tryed to to run de server :
$ rails server
Could not find gem 'rails (= 4.0.2) ruby' in the gems available on this machine.
Run `bundle install` to install missing gems.
I have tryed to install rvm and rbenv, but nothing works in the way tutorials says it should. My feeling is that I missed something in the begynning, but I dont know what.
Could you please help me ?
Thanks
Alex
You need to update gem lock and all dependency
For that please execute below command,
gem update --system
Now You can install json gem using ,
gem install json
Try above command and let me know if you still face same thing. Above things works fine for me:D

Resources