'Undo-ing' changes to Gem source - ruby

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.

Related

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

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

gem install with file system as source installs wrong gem

I have just started working with Ruby. I am trying to install a gem with local file system as source.
$gem source
*** CURRENT SOURCES ***
file:///home/fox/shared/
when i try to install 'bundler' gem it actually installs 'bundler-unload' gem as below.
$gem install bundler --bindir /usr/bin --no-ri --no-rdoc
Successfully installed bundler-unload-1.0.2
1 gem installed
the directory contains both the gems by the way.
bundler-unload-1.0.2.gem
bundler-1.10.6.gem
Is there anything that I am missing here. Why would it install the wrong gem?
I debugged the gem installer code and found the following.
First, the gem installer looks at the current directory to find the gems. It looks for *. It finds two gems (since i was running from the gems source directory) but sorts and reverse orders it and chooses the first one which is not the right gem. It does not do version check also when looking at the local directory. To workaround this i gave 'gem install bundler-1.10.6' which is working. By the way if i run 'gem install' from some other directory it is not able to find any gems from the 'file:' source.

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

Build binary Ruby 2 gems

In our production environment, we are forbidden from having compilers installed (don't ask). Back in the Ruby 1.8.7 days, we would use gem-compile to compile binary gems on a dev workstation and put the binary gem out in our repository. Is anybody aware of any similar methods that work with Ruby 2.0? I know RVM is capable of building custom packages of rubies that can be deployed, but I can't find any way to make it work with gems.
I'd like to come up with something a little less brittle than building everything on a dev box and rsync'ing the entire rvm directory over to the server.
Thanks!
check this part of rvm offline installation - http://rvm.io/rvm/offline#installing-gems :
Online
Create a (fake) project directory: mkdir gems; cd gems
Install bundler: gem install bundler
Create Gemfile: bundle init
Add rails to it: echo "gem 'rails'" >> Gemfile
Install all gems: bundle install
Get gem files: bundle package
Package project: tar czf gems.tgz .
Download bundler from https://rubygems.org/gems/bundler the Download link
Offline
Create a (fake) project directory: mkdir gems; cd gems
Unpack gems: tar xzf gems.tgz
Install bundler: gem install bundler-1.2.1.gem
Install gems: bundle install --local
Nevermind, I found the answer. There is a newer gem called gem-compiler from https://github.com/luislavena/gem-compiler that works with Ruby 2. I didn't think it was working because I inadvertently still had an old copy of gem-compile installed and that was getting executed when I ran 'gem compile'. Anyways, this generates platform specific gems for me that I can install in our production environment.
Cheers and Thanks,
Jason

Resources