Search code examples
rubyrubygemsyt

Can't install `yt-core` gem


Thank you for reading this question.

$ gem install yt
Successfully installed yt-0.32.4
1 gem installed
$ gem which yt
/Users/klee/.rbenv/versions/2.5.4/lib/ruby/gems/2.5.0/gems/yt-0.32.4/lib/yt.rb
$ gem install yt-core
Successfully installed yt-core-0.1.7
1 gem installed
$ gem which yt-core
ERROR:  Can't find Ruby library file or shared library yt-core

I keep trying to install this gem, but it keeps saying "Can't find." Same thing happens to you? How can I install and find this gem? This is the gem I'm trying to install https://rubygems.org/gems/yt-core


Solution

  • From the documentation:

    GEM WHICH

    Find the location of a library file you can require

    So when you call gem which you need to provide an actual module you can require, not just the name of the gem. And if you look at the source for the yt gem you'll see the following structure:

    lib/
      yt.rb
    

    And you'll notice that the content of yt.rb is:

    module Yt
    end
    

    So when you call gem which yt it is able to find that module and tell you where to find it. (lib/yt.rb)

    But if you look at the source for yt-core you'll see there is no file inside the lib/ directory, and instead all files are inside lib/yt:

    lib/
      yt/
        ...
        core.rb
        ...
    

    And the source for core.rb is:

    module Yt
    end
    

    So if you want to find the location of the module, you need to run:

    gem which yt/core
    /Users/foo/.rvm/gems/ruby-2.6.3/gems/yt-core-0.1.7/lib/yt/core.rb
    

    Or yt/channel or yt/group, etc.

    So to use this gem, you would need to include this in your source:

    require 'yt/core'