How to revert back changes in gems - ruby

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

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

Ignoring GEM because its extensions are not built

On both my work and home computers, I recently upgraded Ruby to 2.3.1, using ruby-install. I use chruby as my Ruby switcher.
I started seeing this warning in my terminal:
Ignoring bcrypt-3.1.11 because its extensions are not built. Try: gem pristine bcrypt --version 3.1.11
Ignoring bcrypt-3.1.10 because its extensions are not built. Try: gem pristine bcrypt --version 3.1.10
Ignoring binding_of_caller-0.7.2 because its extensions are not built. Try: gem pristine binding_of_caller --version 0.7.2
Ignoring byebug-9.0.5 because its extensions are not built. Try: gem pristine byebug --version 9.0.5
Ignoring byebug-5.0.0 because its extensions are not built. Try: gem pristine byebug --version 5.0.0
Ignoring concurrent-ruby-ext-1.0.2 because its extensions are not built. Try: gem pristine concurrent-ruby-ext --version 1.0.2
Ignoring debug_inspector-0.0.2 because its extensions are not built. Try: gem pristine debug_inspector --version 0.0.2
On my work, computer, the list was much longer, but easy to resolve. When I tried the suggested gem pristine GEM, it told me it couldn't find the gem, so I ran gem install GEM, and that solved it.
At home, nothing is working.
Things I have tried, from common sense and various other Stack questions:
gem pristine GEM
gem pristine --all
uninstalling and reinstalling the gem
gem update
gem update --system
bundle update
uninstalling and reinstalling bundler
uninstalling and reinstalling rails (Though, it's not a Rails specific problem.)
deleting ~/.bundle/
opening XCode and letting it install some extensions (It did need to do it, but it didn't fix anything.)
running brew doctor and solving all the minor issues, then brew update and brew upgrade
gem install curb (I can't imagine what this gem has to do with this issue, but two different people listed it as the last step of their fix to the same warning.)
I came across this exact issue today - getting warnings like this for gems that weren't even installed!
... Well, it turns out the gems were installed - for a different ruby than the one I had set active with chruby (2.2.3 vs 2.3.1).
Switching to all the different rubies and running gem pristine --all on all of them solved the problem.
I ran into this issue and followed all the same commands as above, even going so far as to remove all my previously installed Ruby versions. However, the error persisted.
Turns out, there were some leftover gems for the various (previously uninstalled) versions in ~/.gem/ruby/. After removing the folders I no longer used, the errors disappeared.
I've had this problem today too and it frustrated because I couldn't type because my whole editor flashed red with error messages.
I'm not entirely sure what exactly caused it but I believe it's because we have multiple ruby versions OR multiple ruby version managers installed and they overwrite each other and otherwise mess up your paths towards the gems.
The gem command also gets overwritten when you have rbenv and rvm.
See which ones you've installed by typing;
which rvm
which rbenv
which chruby
If one of those is installed it'll return a path. Then delete them, make sure to completely clean out all the directories and start with a clean install.
Remove
Here's what I did for rvm;
rvm implode
gem uninstall rvm
rm -rf ~/.rvm
rm -rf ~/.rvmrc
Here's what I did for rbenv
First installed https://github.com/meowsus/rbenv-clean, then
rbenv clean
sudo apt-get remove rbenv
rm -rf ~/.rbenv
Reinstall
Then you have a clean home directory to work from. I reïnstalled rbenv with How to install Ruby 2.1.4 on Ubuntu 14.04. And finally;
rbenv rehash
In my case the warning itself has suggested the solution , so I just run them one by one.
Ignoring bigdecimal-2.0.0 because its extensions are not built. Try: gem pristine bigdecimal --version 2.0.0
Ignoring date-3.0.1 because its extensions are not built. Try: gem pristine date --version 3.0.1
Ignoring dbm-1.1.0 because its extensions are not built. Try: gem pristine dbm --version 1.1.0
Ignoring etc-1.1.0 because its extensions are not built. Try: gem pristine etc --version 1.1.0
Here an example:
gem pristine bigdecimal --version 2.0.0
so running the command of each line has solved my problem.
I did everything mentioned above including
xcode-select --install
reinstall ruby
reinstall all gems
gem pristine --all
but the issue was the same for me.
I just rebooted my Mac as the last hope, and the warning messages are disappeared.
Weird, but if anyone's struggling with this issue after trying everything on StackOverflow, try reboot your machine.
Running gem pristine --all didn't help at first, but then I realized: the script I was running began with the line:
#!/usr/bin/ruby
On my macOS system (Catalina, but I don't think it matters), this points to the Ruby that came with the system, not the one installed by RVM. Running gem pristine --all was fixing up the RVM installation, but my script was calling a different version of Ruby.
The fix for me was to use the env command to call whichever Ruby is specified in the current shell's PATH. Changing the top line of the script to this fixed it:
#!/usr/bin/env ruby
Adding my own flavor here. I use rbenv installed via Homebrew and was getting four of these "ignoring... extensions not built" messages. Specifically:
Ignoring bcrypt-3.1.12 because its extensions are not built. Try: gem pristine bcrypt --version 3.1.12
Ignoring bindex-0.5.0 because its extensions are not built. Try: gem pristine bindex --version 0.5.0
Ignoring bootsnap-1.3.2 because its extensions are not built. Try: gem pristine bootsnap --version 1.3.2
Ignoring byebug-10.0.2 because its extensions are not built. Try: gem pristine byebug --version 10.0.2
I tried many things in this thread with no luck. Finally in my case I did:
brew uninstall rbenv
rm -rf ~/.rbenv
brew install rbenv
At this point I was still getting the errors, but now I had only a single Ruby version to contend with:
$ rbenv versions
* system (set by /Users/will/.rbenv/version)
At this point I tried sudo gem pristine --all but was rejected for permissions on the system Gems directory.
So I went through and ran pristine on each gem, like
sudo gem pristine bcrypt --version 3.1.12 (etc)
And finally the errors were gone.
If you have installed RVM, possible you're catching the error because you have installed different versions.
Check and remove useless versions,
but I think this is not good approach.
Anyway errors gone.
rvm list
rvm use ruby-version
rvm remove ruby-useless-version
After refresh cocoapods, it should be injected in .rvm GEM_HOME
gem uninstall cocoapods
gem install cocoapods
Probably pod COMMAND will throw the error about minitest gem, so – gem install minitest
Running Mac OS Catalina, brew and rbenv ...
Having come across this exact problem today, and gone through all the answers here I eventually stumbled across another reason for this error:
Ignoring nokogiri 1.10.7 because its extensions are not built. Try: gem pristine nokogiri --version 1.10.7
And of course gem pristine did no work.
My problem was a hard coded GEM_HOME and GEM_PATH environment variables which were overriding rbenv.
So, check that you haven't set GEM_PATH and GEM_HOME in ~/.zshrc
TL;DR - Ruby gems don't like Rubies running from symlinks or moved from where they were built (because of embedded shebangs)
If the Ruby directory is invoked or environment vars point to a symlink'ed directory, or are copied or renamed, this message is likely. I am using chruby and was symlinking /opt/rubies/ -> /usr/local/ruby/, but Ruby's dynamic library-finding logic doesn't play well with this.
The solution in my case was to replace the symlink with actual rubies in /opt/rubies/ and run gem pristine --all in each Ruby. For others using RVM or Rbenv, good luck with that without starting over from scratch.
This may not be your exact issue, but hopefully it helps.
This is an old thread, but I just came across this issue myself.
You don't need to restart your machine, you just need to refresh your environment, you can do this with the rehash command:
rehash
From the man page: rehash command re-computes the internal hash table of the contents of directories listed in the path environmental variable to account for new commands added.
Most comments here are on the right track. This problem often occurs after a Ruby version upgrade. I reviewed the gem command code and here is the gist of it.
Extensions are compiled into the gems/gem/ext subdirectory of the gems home directory. For example, on my Cygwin installation (and similarly under Raspbian), the BigDecimal extension is compiled into
/usr/share/gems/gems/bigdecimal-1.3.5/ext/bigdecimal/bigdecimal.so.
However, this is not where the extension is referenced when executed - that is from
/usr/lib/gems/ruby/ver/gem. Again using BigDecimal, the extension file when executed is loaded from
/usr/lib/gems/ruby/2.3.0/bigdecimal-1.3.5/bigdecimal.so
Here is the key: in this same directory, there is an empty tag file
/usr/lib/gems/ruby/2.3.0/bigdecimal-1.3.5/gem.build_complete
When the gem command starts up, it refers to the gems/specifications directory to get a list of installed gems and information as to whether they have extensions. If a gem does have extensions, gem (among other sanity checks) looks for the tag file gem.build_complete. If that is not found, it emits the error message "Ignoring gem because its extensions are not built".
Any action which rebuilds all extensions will fix this problem. Or, as total hack, if you in a hurry and brave, you can try copying all contents of /usr/lib/gems/ruby/oldver to /usr/lib/gems/ruby/newver e.g.
cd /usr/lib/gems/ruby
cp -nv 2.3.0/* 2.6
This is also a problem when you're developing on Mac and then build a Docker image:
https://forums.aws.amazon.com/thread.jspa?messageID=879802&tstart=0
When you do a "bundle install --deployment", bundler will create a
vendor directory w/ your gems in it. Note that whilst this includes
your gems in the local folder, it will only include the native
extensions for your platform. As you're on macOS this will be Darwin.
You'll need to do repeat the process on a 64-bit x86 linux
environment.
Libby's suggestion to just start a new terminal session (which she commented on Sebastian Kim's answer) worked for me. Much quicker than any of the others too so I wanted to make it an answer so it was more visible.
I had this problem but only when I was starting tmux session using tmuxinator.
Turned out it's because I'm using tmuxinator from brew instead of installing it using gem install. Maybe using chruby at the same time contributed to the problem as well.
p/s: I also removed unused ruby from ~/.gem/ruby but I doubt that's the reason this issue was resolved for me.
Uninstall and reinstall of Vagrant also works. There's an unistall.tool bash script included in the installer .dmg image that will remove Vagrant.
Found this solution here: Updating Vagrant and Gems Extentions Not Built In
I had the same issue and I'm using rbenv. For some reason my global rbenv setting went missing. In order to fix this problem I set the global version to one of my rbenv versions... for instance:
rbenv global 2.5.1
On my case I was trying to run pristine --all but I was getting:
Ignoring ffi-1.11.1 because its extensions are not built. Try: gem pristine ffi --version 1.11.1
Ignoring jaro_winkler-1.5.3 because its extensions are not built. Try: gem pristine jaro_winkler --version 1.5.3
Ignoring psych-3.1.0 because its extensions are not built. Try: gem pristine psych --version 3.1.0
/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': incompatible library version - /.gem/gems/psych-3.1.0/lib/psych.bundle (fatal)
Then, I deleted the content on Users/{{user.name}}⁩/⁨.gem⁩ then as I needed to run bundle install --force, it reinstalled everything, then the command pristine --all worked as expected
This solution worked for me for RubyMine IntelliJ
I had two different terminals being used and RVM and ruby<Version>.
Solution:
I had to switch it to the RVM version for the errors to go away in Preferences>Languages&Frameworks>Ruby SDK
Errors:
Ignoring executable-hooks-1.6.0 because its extensions are not built. Try: gem pristine executable-hooks --version 1.6.0 rubymine
Ignoring gem-wrappers-1.4.0 because its extensions are not built. Try: gem pristine gem-wrappers --version 1.4.0
If you are using rvm like me, the fix could a simple:
rvm get stable
rvm reload
As stated in this answer https://apple.stackexchange.com/a/192513
I have executed these commands in Terminal and worked for me:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install ruby, it may need sudo (sudo brew install ruby).
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
sudo gem pristine --all
In Ubuntu this worked for me.
source ~/.bash_profile
sudo gem pristine --all

Uninstalling gems massively

I'm using ruby 2.2 and I would like to know is there is a way to uninstall all gems in my gemlist in one command. Something like gem uninstall * or gem uninstall -A ?
gem uninstall --all
Uninstalls every gem in your gem list.

'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.

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