How do I force Bundler to reinstall all of my gems? - bundler

How do I force Bundler to reinstall all of the gems in my gemfile? Or, how do I force Bundler to uninstall all of the gems it installed so I can then reinstall them myself?
I saw rails bundle clean, but this question explains how to remove gems that bundle installed but are no longer in the gemfile.
And How to reinstall a gem using bundler explains how to reinstall a single gem. I would like to reinstall all of my gems at once.

bundle install --redownload
See the reference for bundle install: https://bundler.io/v2.2/man/bundle-install.1.html
or
bundle install --force
For older versions of bundler

Brutish but clever:
Comment out your entire Gemfile. (Don't delete it)
bundle clean
Restore your Gemfile.
bundle install

You can also delete the vendor directory and do bundle install again.

If you completely want to reinstall everything from scratch you can just, locate your gem dir, for example if you use rvm it would be ~/.rvm/gems
then locate your ruby version alongside with gemset for example ruby-2.7.0#some_particular_gemset (it will be a dir) and then just delete it.
rm -rf ruby-2.7.0#some_particular_gemset
bundle install

Another way to deal with gem problems can be to sudo gem clean instead of reinstalling everything

Related

How to start over with a clean gems install for jekyll?

I've been working on a blog using Jekyll so I installed Ruby with this command from the Jekyll doc:
sudo apt-get install ruby ruby-dev build-essential
Then I installed the gems directory to my home folder. I tried out a lot of different themes and just run bundle install when my terminal said I was missing any dependencies. Now I have a lot of packages installed inside the gems folder. Is there a way for me remove unnecessary gems and start over without uninstall gems?
It is highly recommend to not use system ruby but use a ruby version manager. One reason is that you won't have to use sudo before your gem commands.
If you want to remove all your current gems you should be able to just do
gem uninstall --all
But you might need to prepend it with sudo gem uninstall --all
If you intend to do any longer term work / multiple projects with ruby, I recommend using RVM. You can find detailed install instructions here
Some prefer rbenv however it's install instructions seem to be focused on MacOS, so if you're on linux, I dunno.
You can just run:
gem uninstall [gemname]
to remove them one at a time.

Bundler install custom path issue

gem env shows
GEM PATHS:
/usr/local/share/gems
I would like to use bundle install --deployment --path=/usr/local/share/gems to install my bundled gems.
The problem is that the bundle install creates a folder ruby and puts the gems folder inside the ruby folder.
When this happens my ruby code is unable to find the gems in its default path.
Looks like I am missing some configuration parameter. Help please.
MaurĂ­cio Linhares comments in the question has resolved the issue.
When using bundler to install gems use bundle exec ruby. When the bundle install --deployment happens the path information goes into .bundle/config
bundle exec ruby path-to-ruby-script.rb
The above execution Will find the gems installed by the bundle command.
Alternatively, if you want to force installation to the system gem location, I believe bundle install --deployment --system will do what you want.

'Undo-ing' changes to Gem source

I was debugging a gem a while ago and accidentally left in some code that causes my project to hang when it makes use of that gem. How can I restore the clean source? Is the only option to uninstall and reinstall?
The command
gem pristine foo
Does this for the gem of that name. You can also pass --all to rebuild all gems. This works by comparing what's in the .gem file (which is a tar archive in disguise) with the actual files. More details in the documentation
Uninstall that gem with gem uninstall <gem_name> and then reinstall via gem install <gem_name> or bundle install.

How to revert back changes in gems

So I was debugging locally installed gems:
/Users/myUser/.rvm/gems/ruby-1.9.3-p484#12wbt-engine/gems/locomotive_liquid-2.4.2
And now I removed the this folder. Hence I'm wondering if there is any way to restore it?
DOESN'T WORK:
bundle install
bundle update
What you need is gem pristine
e.g:
gem pristine locomotive_liquid
Try:
gem uninstall locomotive_liquid
bundle install

Why won't this gem be uninstalled

i installed a gem from this repository using this in my Gemfile :
gem 'copy_carrierwave_file', github: 'equivalent/copy_carrierwave_file'
when i'm trying to uninstall it using :
gem uninstall copy_carrierwave_file
nothing is shown like copy_carrierwave is uninstalled successfuly from....
then if i type :
bundle show copy_carrierwave_file
it still show me the location of this gem
How i can uninstall it ?
Since git, github, and path located, or development gems are controlled by bunlder, you have just to remove put to delete gem from Gemfile. And you even don't need to run bundle install again.
$ bundle show session
Could not find gem 'session'.
Bundle Clean. Since the gems were installed using bundler, they have to be uninstalled using bundler too!
First, remove the line gem 'copy_carrierwave_file', github: 'equivalent/copy_carrierwave_file' from your Gemfile
Then, bundle clean with dry-run (just in case you see gems you don't want to remove):
bundle clean --force --dry-run
If you want to remove those gems, clean it:
bundle clean --force

Resources