Cannot Find Gem IO-Console - ruby

When I run gem search -l -d I get io-console included in my list
io-console (0.4.5)
Author: Nobu Nakada
Homepage: http://www.ruby-lang.org
License: BSD-2-Clause
Installed at (default): /Library/Ruby/Gems/2.3.0
Console interface
However, when I run ls -la /Library/Ruby/Gems/2.3.0, no folder or file called io-console exists in that directory or in the /gems directory within it. Where is this gem located?

This gem comes pre-installed with Ruby itself. It is one of the core libraries and is not actually installed as Ruby code but a shared library:
Gem.find_files('io/console')
=> ["/usr/lib/x86_64-linux-gnu/ruby/2.5.0/io/console.so"]

Related

FreeBSD Could not find gem in any of the sources

I am trying to bundle on FreeBSD and it cannot find the grpc gem. I installed the grpc 1.30.2 version using a FreeBSD package but it cannot find the system gem.
I'm hoping there is a bundle config setting to find and use the system gem which is already built and intalled.
The error I get is:
An error occurred while installing grpc (1.30.2), and Bundler cannot continue.
Make sure that `gem install grpc -v '1.30.2' --source 'https://rubygems.org/'` succeeds before bundling.
In Gemfile:
grpc
* bundle install
Warning: the running version of Bundler (2.0.2) is older than the version that created the lockfile (2.2.11). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
/usr/local/lib/ruby/site_ruby/2.7/rubygems/package.rb:509: warning: Using the last argument as keyword parameters is deprecated
/usr/local/lib/ruby/site_ruby/2.7/rubygems/package.rb:509: warning: Using the last argument as keyword parameters is deprecated
/usr/local/lib/ruby/site_ruby/2.7/rubygems/package.rb:509: warning: Using the last argument as keyword parameters is deprecated
/usr/local/lib/ruby/site_ruby/2.7/rubygems/package.rb:509: warning: Using the last argument as keyword parameters is deprecated
Some gems seem to be missing from your vendor/cache directory.
Could not find grpc-1.30.2 in any of the sources
* Visruleparser
A extras/visruleparser.pl
Export complete.
* precompile assets
Could not find grpc-1.30.2 in any of the sources
Run `bundle install` to install missing gems.
My Gemfile has these lines
source 'https://rubygems.org'
gem 'grpc', '1.30.2'
gem 'grpc-tools', '1.30.2'
The Gemfile.lock has these
grpc (= 1.30.2)
grpc-tools (= 1.30.2)
These FreeBSD packages are installed
>pkg info -x grpc
grpc-1.22.0_4,2
rubygem-grpc-1.30.2
>gem list grpc
*** LOCAL GEMS ***
grpc (1.30.2)
Listing remote gems shows nothing on FreeBSD
>gem list --remote -all gprc
*** LOCAL GEMS ***
But on macOS I get these (among others)
>gem list --remote --all grpc
grpc (1.37.0 ruby universal-darwin x64-mingw32 x86-linux x86-mingw32 x86_64-linux,
1.36.0 ruby universal-darwin x64-mingw32 x86-linux x86-mingw32 x86_64-linux,
...
1.30.2 ruby universal-darwin x64-mingw32 x86-linux x86-mingw32 x86_64-linux,
...
The gem is installed in the directory /usr/local/lib/ruby/gems/2.7/gems/grpc-1.30.2 with a src subdirectory and a ruby subdirectory below that.
>ls /usr/local/lib/ruby/gems/2.7/gems/grpc-1.30.2/src/ruby
bin ext lib pb spec
Environment
FreeBSD 11.4
Ruby 2.7.2p137
RubyGems 3.0.8
Bundler 2.1.4
Looks like this may be my fault. The gem packages purposefully remove the cache dir from the gem. This was originally added here:
https://cgit.freebsd.org/ports/commit/Mk/bsd.ruby.mk?id=8d77480356f58d6d8d1c69884d1ba9cc98ed383a
and lives on here:
https://cgit.freebsd.org/ports/tree/Mk/Uses/gem.mk#n111
${RM} -r ${STAGEDIR}${PREFIX}/${CACHE_DIR} 2> /dev/null || ${TRUE}
This was added because so many gems include large amounts of stuff that is never used in the cache dir, including complete copies of source, intermediate build output, etc. that shouldn't really be packaged.
If you're building your own packages you can try the line from gem.mk that removes the cache dir. Otherwise, we may need to revisit this upstream. Regardless, you should probably open a bug upstream at:
https://bugs.freebsd.org/bugzilla/
But there are tradeoffs and I'm not sure about the use case of bundling gems installed from system packages. (I haven't been using Ruby as much recently.)

Jekyll version questions

If I run jekyll -v in terminal, I got this:
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/universal-darwin19/rbconfig.rb:229: warning: Insecure world writable dir /usr/local/opt in PATH, mode 040777
jekyll 4.1.0
But if I run gem list jekyll, it says I have another version of jekyll:
*** LOCAL GEMS ***
jekyll (2.4.0)
jekyll-coffeescript (1.2.2)
jekyll-gist (1.5.0)
jekyll-paginate (1.1.0)
jekyll-sass-converter (1.5.2)
jekyll-watch (1.5.1)
Does it mean I have two different versions of Jekyll installed? and how can I choose to use the old version 2.4.0? and is it possible to uninstall the 4.1.0?
Thanks
I am answering both of your questions:
How can I choose to use the old version 2.4.0?
So, it is actually done through Gemfile in the project. Just mention gem 'jekyll', '2.4.0' in your Gemfile.
Is it possible to uninstall the 4.1.0?
Yes. Run gem uninstall Jekyll --version 4.1.0

Uninstalling Ruby gems

user#machine:~$ gem list
*** LOCAL GEMS ***
bigdecimal (1.2.8)
did_you_mean (1.0.0)
io-console (0.4.5)
json (1.8.3)
minitest (5.8.4)
net-telnet (0.1.1)
power_assert (0.2.7)
psych (2.0.17)
rake (10.5.0)
rdoc (4.2.1)
sass (3.4.23)
test-unit (3.1.7)
user#machine:~$ sudo gem uninstall rake
ERROR: While executing gem ... (Gem::InstallError)
rake is not installed in GEM_HOME, try:
gem uninstall -i /usr/share/rubygems-integration/all rake
user#machine:~$ sudo gem uninstall -i /usr/share/rubygems-integration/all rake
Remove executables:
rake
in addition to the gem? [Yn] Y
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/share/rubygems-integration/all/bin directory.
user#machine:~$ ls /usr/share/rubygems-integration/all/
specifications
user#machine:~$
I can not uninstall this gem in particular, neither use it :(
If seems that it doesn't exist.
My ruby verison is 2.3.1.p112
Ideally you would use RVM or rbenv to create a local sandbox and handle your Ruby install and gems instead of the system default. Then you won't have to use sudo you can just use gem uninstall <gem>. It doesn't let you have access for a reason, so it's harder to accidentally mess up the system Ruby.
If you can just read these install directions to get set up with RVM and then install the gems you used previously in your new environment. It'll save you a lot headaches in the future managing Ruby and gems.
--
If you don't want to do that you could try this answer
Try this answer from this related question.
gem list -d 'name of gem' and note the "Installed at:" location
sudo gem uninstall 'name of gem' -i 'the path noted above'
If it still returns a permissions error. Create a folder /bin, in the path above. Continue uninstalling as in step 2, still using the original path (/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8).
sudo is not a magic wand that casts a spell “do it anyway.”
When you list your gems, you execute plain gem list from the user. It lists gems installed for the user. Afterwards you try sudo gem uninstall rake. Why do you expect superuser’s list of gems being the same as user’s one?
To remove user’s gems, listed with gem list, use gem uninstall rake. Without sudo.
To list superuser’s gems, that you were tried to remove with sudo gem uninstall rake, use sudo gem list. With sudo.
More info on sudo: http://aplawrence.com/Basics/sudo.html

How to reinstall a gem using bundler

I did a bundle show and get the complete path to a gem directory.
Unfortunately, I removed the directory using rm -r gem_path. Then my rails app isn't working anymore. If I try start server or start rails console it outputs the following error:
<class:Application>: uninitialized constant MyAPP::Application::Gem (NameError)
What should I do to have it back?
I tried bundle install or bundle update in hope of forcing the bundle to search the gem and install it back, but didn't work.
I also tried delete the Gemfile.lock and run bundle install. Nothing changed, same error.
The gem in question is Act as taggable on.
If using rbenv, this will let you completely uninstall and re-install a gem such as rmagick:
First: Try a simple uninstall/reinstall
gem uninstall rmagick
bundle install
If that doesn't work, you can remove all trace of the installed gem. Find your gem installation location:
bundle show rmagick
BUNDLE_DIR=$(dirname $(dirname $(bundle show rmagick)))
echo $BUNDLE_DIR
Your gem installation prefix will either be the default e.g. ~/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0 or something you set e.g. .vendor
Clear out the gem directory:
rm -rf $BUNDLE_DIR/gems/rmagick-*
Clear out the compiled gem cache:
rm $BUNDLE_DIR/cache/rmagick*.gem
Also clear out bundler's spec cache:
rm $BUNDLE_DIR/specifications/rmagick*gemspec
Then you can re-install:
bundle install
You can always use:
gem pristine acts-as-taggable-on
pristine - Restores installed gems to pristine condition from files located in the gem cache
If you just want to restore the gem for the current project you should run:
bundle exec gem pristine acts-as-taggable-on
First I did a gem q --L, the shortcut for gem query --local. It outputs me the all the local gems installed.
actionmailer (3.2.8, 3.2.6, 3.2.1, 3.1.0)
actionpack (3.2.8, 3.2.6, 3.2.1, 3.1.0)
activemodel (3.2.8, 3.2.6, 3.2.1, 3.1.0)
activerecord (3.2.8, 3.2.6, 3.2.1, 3.1.0)
activeresource (3.2.8, 3.2.6, 3.2.1, 3.1.0)
activesupport (3.2.8, 3.2.6, 3.2.1, 3.1.0)
acts-as-taggable-on (2.3.3)
...
And then, following DVG advice, I uninstalled the gem using its correct name gem uninstall acts-as-taggable-on and ran bundle install. After that I was able to rails c or rails s again without any problem.
From project directory in terminal
gem uninstall gem_name
If using RVM with gems in ~/.rvm/, this works if bundle is not re-installing a gem.
First, delete the gem source:
bundle show $GEM
rm -rf $PATH_TO_GEM
Clear out the compiled gem cache:
rm -rf ~/.rvm/gems/ruby-$RUBYVERSION[#$GEMSET]/cache/$GEM.gem
Also clear out bundler's spec cache:
rm -rf ~/.rvm/gems/ruby-$RUBYVERSION[#$GEMSET]/specifications/$GEM*gemspec
Then you can re-install:
bundle install
bundle exec gem uninstall <gem_name> - uninstalls gem from the bundle (the <app_root>/vendor/bundle/ruby/2.3.0/gems/ path). This is equivalent to the answer #ioquatix gave, but is the slightly more convenient solution that he was looking for.
gem uninstall <gem_name> - uninstalls gem only from the global gemset in the system
If you've installed into ./bundle/vendor or similar, you need to remove the gem first but explicitly specify the GEM_HOME, e.g.
GEM_HOME=./vendor/bundle/ruby/2.3.0/ gem uninstall rmagick
This is by far the simplest way to uninstall gems installed using bundler into a vendor directory. Ideally, there would be a command bundle uninstall or bundle reinstall, etc.
If your goal is to simply reinstall, the following command will help:
GEM_HOME=./vendor/bundle/ruby/2.3.0/ gem uninstall rmagick && sudo -u http bundle install
If you're like me and have several web-applications under a directory (e.g. /srv/http), the following does it in all directories:
cd /srv/http
for d in ./*/ ; do (cd "$d" && sudo -u http GEM_HOME=./vendor/bundle/ruby/2.4.0/ gem uninstall --force rmagick && sudo -u http bundle install); done
If you're trying to reinstall rake, gem pristine rake will fail with Skipped rake-10.X.X, it is a default gem and bundle won't install it either, because it can't uninstall it.
If you're using rvm, it seems the easiest was is simply to do a rvm reinstall 2.x.x. At least for me, rvm repair all also didn't help.
The same probably goes for all other default gems. I'll just list them here so that the desperate googlers find some help:
bigdecimal
drip
io-console
json
minitest
psych
rake
rbtree
rdoc
test-unit

How to remove installed ri and rdoc?

How can I remove the ri and rdoc of installed gems? Thanks
You can simply remove the doc directory in the RubyGems installation directory.
rm -r `gem env gemdir`/doc
On Mac OS X by default, it's /Library/Ruby/Gems/1.8/doc.
Keep in mind that there might be several installation directories for RubyGems.
RubyGems will try to install to your user directory (something like ~/.gem/ruby/1.8/) if it can't access the normal installation directory (e.g. you installed a gem without sudo).
RVM also installs RubyGems for each Ruby it installs which will contain a doc directory containing rdoc and ri files (e.g. ~/.rvm/gems/ruby-1.9.2-preview1/doc).
This will merely remove existing files, but new ones will come with new installations anyway, unless you use the --no-document flag for gem install or make it a default.
It worked for me when I tried this:
gem rdoc <gem name> --no-ri --overwrite
Then you can remove only ri of the gem, and leave the gem itself. I don't see we need any other way around for this.
I just had this problem to, after thinking it would be a good idea to have some local rdoc for the train etc, I completely filled up my disc!
So, I bit the bullet, and did it (the hard way).
First, this is how I got in this stupid predicament :-
$ gem install rdoc-data
$ rdoc-data --install
$ gem rdoc --all --overwrite
To undo this, I thought I'd uninstall the gems, and then install them as needed (but without rdoc!)
Get list :-
$ gem list
*** LOCAL GEMS ***
aasm (2.1.1)
actionmailer (3.2.3, 3.2.2, 3.1.4, 3.1.3, 3.1.1, 3.1.0, 2.3.8, 2.3.5)
actionpack (3.2.3, 3.2.2, 3.1.4, 3.1.3, 3.1.1, 3.1.0, 2.3.8, 2.3.5)
active_support (3.0.0)
... +100 ...
Copy and search/replace \(.*\) with '\'
Bulk uninstall :-
$ gem uninstall actionmailer \
actionpack \
active_support \
... 100 more ...
ZenTest \
-a -x -I
Watch as the disc gains GB's of free space! (~11GB!)
Twas a stupid idea in the first place, and my solution may be just as much so, but it worked.

Resources