Rails upgrade is complaining about older bundler version - ruby-on-rails

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.

Related

Messed up! How to uninstall gem bundler?

I kinda messed up when trying to solve a problem.
I was looking up some solutions to solve this problem
cap staging deploy
rbenv: cap: command not found
The `cap' command exists in these Ruby versions:
3.0.0
One solution I came across has something to do with gem install bundler
To check my gem bundler, I ran gem list bundler which listed nothing so I ran gem install bundler which installed bundler (2.2.23).
However, when I ran bundle install, I get this:
Traceback (most recent call last):
2: from /Users/kiki/.rbenv/versions/2.5.1/bin/bundle:23:in `<main>'
1: from /Users/kiki/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems.rb:308:in `activate_bin_path'
/Users/kiki/.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)
So I wanted to uninstall/undo the steps I took. However, typing in gem uninstall bundler and gem uninstall bundler -v 2.2.23 didn't work! It kept returning Gem 'bundler' is not installed and in fresh terminal, when I ran the command again, it returns Gem bundler-2.2.23 cannot be uninstalled because it is a default gem.
How do I fix it?

RubyMine 2019.1 can't run rake tasks

I got a Rails project that uses Ruby 2.5.3 and I can run bin/rake --tasks from the terminal just fine:
$ rbenv version
# 2.5.3 (set by /Users/me/myproject/.ruby-version)
However, I get a message each time RubyMine telling me that rake --tasks can't be executed.
This is more of a nuisance than a real problem but I still want to get this fixed.
Interestingly, a different rubyframework 2.6.0 is used and it is the "native" ruby rather than one of my rbenv installations:
Error:[rake --tasks] /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': Could not find 'bundler' (2.0.2) required by your /Users/besi/Dropbox/projects/boexli/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:2.0.2`
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:302:in `activate_bin_path'
from /usr/bin/bundle:23:in `<main>'
Error:[rake --prereqs] /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': Could not find 'bundler' (2.0.2) required by your /Users/besi/Dropbox/projects/boexli/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:2.0.2`
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:302:in `activate_bin_path'
from /usr/bin/bundle:23:in `<main>'
I think, if I could change that framework 2.6 to my default 2.5.3 the issue would be resolved, but I can't seem to find that setting.
The SDK from which that task is executed does not show up the SDK Dialog at all.

bundle install not working in my project 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

Webpacker Error While Creating Ruby On Rails App

$ rails 6.0.2 new sample_app2
.
.
.
Using web-console 4.0.1
Using webdrivers 4.1.3
Using webpacker 4.2.2
Bundle complete! 17 Gemfile dependencies, 75 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
run bundle binstubs bundler
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Skipped bundle since it already exists.
If you want to overwrite skipped stubs, use --force.
run bundle exec spring binstub --all
* bin/rake: Spring inserted
* bin/rails: Spring inserted
rails webpacker:install
Traceback (most recent call last):
4: from /home/emsawy/.rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:24:in `'
3: from /home/emsawy/.rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:24:in `eval'
2: from /home/emsawy/.rvm/gems/ruby-2.6.3/bin/yarn:23:in `'
1: from /home/emsawy/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/bundler/rubygems_integration.rb:400:in `block in replace_bin_path'
/home/emsawy/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/bundler/rubygems_integration.rb:372:in `block in replace_bin_path': can't find executable yarn for gem yarn. yarn is not currently included in the bundle, perhaps you meant to add it to your Gemfile? (Gem::Exception)
Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/
Also after performing Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/
I got the same result
$ yarn -v
[DEPRECATION] The trollop gem has been renamed to optimist
and will no longer be supported. Please switch to optimist
as soon as possible. Yarn v0.1.1 2011 Jesper Kjeldgaard
$ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
$ rails -v
Rails 6.0.2.1
You installed yarn as a gem https://rubygems.org/gems/yarn and this is wrong.
Now you should do:
Uninstall this gem, gem uninstall yarn
On mac os brew install yarn if other platform then look here: https://yarnpkg.com/lang/en/docs/install/#debian-stable
Check version, should be something like:
yarn -v
1.21.1
Got the same error.
First uninstall yarn by commanding gem uninstall yarn.
It will ask yn, Enter yn
Next run: command gem update
Finally check yarn --version

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)"

Resources