Rails: How to change Bundler default version - ruby-on-rails

bundler (2.0.1, default: 1.17.2)
How could I change the default to 2.0.1

Following https://bundler.io/guides/bundler_2_upgrade.html#upgrading-applications-from-bundler-1-to-bundler-2, here's what worked for me:
gem install --default bundler
gem update --system
bundle update --bundler

What helped me is to delete the current default manually from the folder
lib\ruby\gems\2.6.0\specifications\default\
and then install fresh bundler as usually
gem install bundler
or as default
gem install --default bundler

I had this same concern when trying to setup Bundler gem 2.2.11 as the default gem on my machine.
Here's how I achieved it:
First, I listed and uninstalled all other versions of the Bundler gem because I did not need them:
gem list bundler
gem uninstall bundler
If you encounter an error like this
Gem bundler-2.1.4 cannot be uninstalled because it is a default gem
Simply run the command below to get your ruby installation directory:
gem environment | grep "INSTALLATION DIRECTORY"
This should display an output like this. In my case my ruby version was 2.7.2:
- INSTALLATION DIRECTORY: /home/mycomputer/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0
Next, navigate to the specifications/default directory of the INSTALLATION PATH:
cd /home/mycomputer/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/specifications/default
Remove/delete the bundler.gemspec file that you have there. In my case it was bundler-2.1.4.gemspec, so I ran the command:
rm bundler-2.1.4.gemspec
Next, I installed the Bundler gem 2.2.11 and made it the default gem:
gem install --default bundler -v 2.2.11
Next, I listed my Bundler versions:
gem list bundler
Finally, I updated my gems to use the newly installed Bundler:
gem update --system
That's all.
I hope this helps

You need to remove .spec file to remove the gem.
Steps:
gem env – try to search in provided list under GEM PATHS, in specifications/default
remove there bundler-VERSION.gemspec
install bundler, if you don't have specific: gem install bundler:VERSION --default

gem install --default bundler:<version>

You need to know where the default specs are, so use gem environment to find out.
the steps I used were:
gem environment
# note INSTALLATION DIRECTORY
cd <installation_dir>
cd specifications/default
rm bundler-2.1.4.gemspec
gem install --default bundler -v 2.2.11

Remove all default bundler versions.
Commands:
$ gem environment
$ cd INSTALLATION DIRECTORY
$ cd specifications
$ cd default
$ rm bundler version
$ gem install bundler

Related

rails bundler version issue

I have rails project working on Ubuntu.
Now I installed WSL on another machine and cloned the very same project.
Now when I try to install bundler with
gem install bundler
it installed bundler 2.0.2 and on bundle install it gives error:
Could not find gem 'bundler (< 2.0, >= 1.3.0)', which is required by gem 'rails (~> 5.0.0)'
Now I looked at the gemfile.lock it was bundled with 1.16.4, I installed it with
gem install bundler -v '1.16.4'
Now I do a simple bundle install, then it uses 2.0.2, so I have to do
bundle _1.16.4_ install
It completed successfully, but now when I am trying to do rails db:create, it says
The git source https://github.com/activerecord-hackery/ransack.git is not yet checked out. Please run bundle install before trying to start your application
What's wrong here?
Uninstall bundler 2.0.2:
gem uninstall bundler -v 2.0.2
If you still have problem, you can use:
bundle exec rails db:create
You can update to using bundler 2.x if possible with:
bundle update --bundler
This will change the BUNDLED_WITH version in Gemfile.lock.
see: https://bundler.io/guides/bundler_2_upgrade.html
You could also set the default bundler version:
bundler config default 1.16.4
gem list bundler
However I have found this to be a bit error prone.
Try to remove all your gems (go to the gems folder of your ruby, remove the specifications folder and the gems folder),
gem list should be more or less empty
gem install bundler
And try to bundle install again from scratch.

I git cloned a repo and I cannot run it on localhost because missing gem and cannot bundle install

I git cloned a repo. I cannot run it on localhost with rails server because terminal says
Could not find activesupport-4.2.5 in any of the sources Run bundle
install to install missing gems.
When I run bundle install, I get
An error occurred while installing pg (0.18.4), and Bundler cannot
continue. Make sure that gem install pg -v '0.18.4' succeeds before
bundling.
I have rails 4.2.3, and the repo's Gemfile has gem 'rails', '4.2.5'. I don't know if this matter
Gem pg is Postgres driver, it only can be installed, if corresponding headers and libraries are present and can be accessed.
Most probably just installing postgres will fix it. If you're on a Mac with homebrew - brew install postgresql
Install postgresql.
Remove Gemfile.lock
Add gem 'pg' in your gemfile
execute bundle install
1: Remove Gemfile.lock if Gemgile.lock present in your project
2: add gem 'pg' # in Gemfile
3: Run bundle install
Hope this help you !!!
Run
sudo env ARCHFLAGS="-arch x86_64" gem install pg -v '1.18.4'
Now try running bundle install again.
I used a combination of #Chakreshwar Sharma and #Vinay's answers to get this working for the metasploit-framework.
Remove Gemfile.lock
Add gem 'pg' in your gemfile
Run apt-cache search postgresql-server-dev
apt-get update && apt-get install postgresql-server-dev-9.5 # Check your version
bundle install --no-deployment
To be honest, I think you could just run:
apt-cache search postgresql-server-dev
apt-cache search postgresql-server-dev-9.5
bundle install
...and you can avoid messing with the Gemfile, but I didn't get to verify it since mine started working after I made the adjustments.

How to move or uninstall gems from default System Ruby folder to RVM?

I have so many issues trying to update from Rails 3.2 to Rails 4.1 following the guide that I decided to uninstall Ruby, Rails and RVM (with all its gems) and start over.
RVM and Ruby Gone. $ rvm remove
But still have a bunch of GEMS that I previously installed.
$gem list
As suggested on this answer, to remove all gems do:
$for i in `gem list --no-versions`; do gem uninstall -aIx $i; done
But I bump again on the error:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory
This is so frustrating! Using sudo does not make the fix either.
Even if I try to uninstall one by one, the system wont let me:
$rails uninstall
Could not find gem 'pg (~> 0.17.1) ruby' in the gems available on this machine.
Run `bundle install` to install missing gems.
Why do I need another Gem to uninstall a Gem?!
Try
for i in `gem list --no-versions`; do sudo gem uninstall -aIx $i; done
This SO question has some ideas: getting rid of ruby gems that won't die
The answer to this SO question has step by step instructions to set it up properly: Removing Gems errors

Rails: "Could not find bundler" (2.2.11) required by Gemfile.lock. (Gem::GemNotFoundException)

When I try to do bundler update I get this error:
.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in
`to_specs': Could not find bundler (>= 0) amongst
[rake-0.8.7, rake-0.8.7, rubygems-update-1.8.4] (Gem::LoadError)
I'm new to Ruby, can someone tell me what would cause this? Rake 0.8.7 is installed.
Make sure you're entering "bundle" update, if you have the bundler gem installed.
bundle update
If you don't have bundler installed, do gem install bundler.
I had this problem, then I did:
gem install bundler
then in your project folder do:
bundle install
and then you can run your project using:
bundle exec rails server
I had the same problem. This worked for me:
run rvm/script/rvm and also add it to your .profile or .bash_profile as shown in https://rvm.io/rvm/install/
use bundle without sudo
If You are using rvm, then try the following command:
rvmsudo gem install bundler
According to another question: Could not find rails (>= 0) amongst [] (Gem::LoadError)
Hope it helped,
Cheers
The command is bundle update (there is no "r" in the "bundle").
To check if bundler is installed do : gem list bundler or even which bundle and the command will list either the bundler version or the path to it. If nothing is shown, then install bundler by typing gem install bundler.
I had the same problem .. something happened to my bash profile that wasn't setting up the RVM stuff correctly.
Make sure your bash profile has the following line:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
Then I ran "source ~/.bash_profile" and that reloaded everything that was in my bash profile.
That seemed to fix it for me.
According to this answer to a similar question, it should be enough:
rvmsudo gem install bundler.
Cheers
If you're using rbenv running rbenv rehash can solve this after you've installed bundler and are still getting the issue.
You may have to do something like "rvm use 1.9.2" first so that you are using the correct ruby and gemset. You can check which ruby you are using by doing "which ruby"
I had this same concern when setup a new Bundler gem version (2.2.11) on my machine.
I was getting the error below:
/home/username/.rbenv/versions/2.7.2/lib/ruby/2.7.0/rubygems.rb:277:in `find_spec_for_exe': Could not find 'bundler' (2.2.11) required by your /home/username/Projects/my_project/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.2.11`
17: from /home/username/.rbenv/versions/2.7.2/bin/rspec:23:in `<main>'
16: from /home/username/.rbenv/versions/2.7.2/bin/rspec:23:in `load'
15: from /home/username/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rspec-core-3.10.1/exe/rspec:4:in `<top (required)>'
14: from /home/username/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rspec-core-3.10.1/lib/rspec/core/runner.rb:45:in `invoke'
Here's how I achieved it:
First, I had already installed the Bundler gem 2.2.11 and made it the default gem:
gem install --default bundler -v 2.2.11
Next, I listed my Bundler versions:
gem list bundler
Finally, I updated my gems to use the newly installed Bundler:
gem update --system
That's all.
I hope this helps
I got this after upgrading to ruby 2.1.0. My PATH was set in my login script to include .gem/ruby/2.0.0/bin. Updating the version number fixed it.
The system might be running "rootless". Try to set the firmware nvram variable boot-args to "rootless=0".
Try to run set of commands:
sudo nvram boot-args="rootless=0";
sudo reboot
After reboot completes, run:
sudo gem install bundler
Can be related to https://github.com/bundler/bundler-features/issues/34 if you are running the command inside another bundle exec. Try using Bundler.with_original_env if that is the case.
For anyone encountering this issue with Capistrano: capistrano isn't able to locate the bundler. The reason might be that you installed bundler under some other gemset where the Capistrano isn't even looking.
List your gemsets.
rvm gemset list
Use a particular gemset.
rvm use 'my_get_set'
Install bundler under that gemset.
gem install bundler
Then, try again with the deploy task.
I resolved it by deleting Gemfile.lock and gem install bundler:2.2.0
In my case I believe I had an old Ruby remaining on the system, not registered on rvm, and even if the path variables and gem list was okay, it would still use the old Ruby during deployments with Capistrano
And then I realized, the Ruby I had installed with rvm wasn't set to the default one. Running
rvm alias create default <rvm_registered_ruby>
Fixed it.
Just in case, I had similar error with bundler 2.1.2 and solved it with:
sudo gem install bundler -v 1.17.3
If you have several bundler versions installed, then you can run specific version of bundle this way: bundle _1.17.3_ exec rspec
Though seems like later bundler versions are pretty buggy (had issues on 3 different projects on 2 operation systems), having one old bundler may work the best, at least this is what I have on my Ubuntu & MacOS
Latest bundler versions may override stable bundler -v 1.17.3.
It can be not easy to remove latest bundler from system, here is what helped me:
Remove default version from gem env gempath: https://stackoverflow.com/a/60550744/1751321
Remove rm bundler.rb && rm -rf bundler folder from load paths: ruby -e 'puts $LOAD_PATH'
Then reinstall stable gem install bundler -v 1.17.3 (Not sudo! it is important)
Script ruby fix_bundler.rb
require 'fileutils'
load_paths = `ruby -e 'puts $LOAD_PATH'`
load_paths.split.each do |path|
target = File.join path, "bundler.rb"
if File.exist? target
puts "Deleting #{target}"
File.delete target
end
target = File.join path, "bundler"
if File.directory? target
puts "Deleting #{target}"
FileUtils.rm_rf target
end
end
Gem.paths.path.each do |path|
path_mask = File.join path, "specifications", "default", "bundler*"
Dir[path_mask].each do |target|
puts "Deleting #{target}"
FileUtils.rm_rf target
end
end
puts "✅ bundler fixed"

Installing Heroku gem to my root directory

How do I install the Heroku gem to my root directory? I tried sudo gem install heroku, but this doesn't seem to work. Any other suggestions? I am working with OSX.
I would not recommend installing gems in locations other than where RVM or gem wants to install the files, but you can override the install location like this:
sudo gem install heroku --install-dir /path/to/install/into
Where /path/to/install/into is where you want to install the gem.

Resources