How to install a downloaded Ruby gem file?

前端 未结 3 836
借酒劲吻你
借酒劲吻你 2021-01-30 21:10

How does \"gem install\" works ? It is not intuitive...

My gem is really here :

[root@localhost Téléchargement]# ll *.gem
-rw-rw-r-- 1 jean jean 16353818         


        
相关标签:
3条回答
  • 2021-01-30 21:30

    Maybe I have not fully understood the question. But if you just want to install a gem that you have on your local machine, all you need to do from the console is go into the directory containing your gem and gem install --local your.gem.

    0 讨论(0)
  • 2021-01-30 21:33

    The problem is that gem install is looking for gems to install in its default directory. You can find out where that is by running:

    $ gem environment
    

    This will give you something like:

    > RubyGems Environment:
    >   - RUBYGEMS VERSION: 1.3.6
    >   - RUBY VERSION: 1.8.6 (2007-09-24 patchlevel 111) [i486-linux]
    >   - INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8
    >   - RUBY EXECUTABLE: /usr/bin/ruby1.8
    >   - EXECUTABLE DIRECTORY: /usr/bin
    >   - RUBYGEMS PLATFORMS:
    >     - ruby
    >     - x86-linux
    >   - GEM PATHS:
    >      - /usr/lib/ruby/gems/1.8
    >      - /home/adminuser/.gem/ruby/1.8
    

    The GEM PATHS locations is where gem install is expecting to find gems to install. So, the solution to your problem would be to copy the gem from its current location to the expected directory, i.e.

    $ cp my.gem /home/adminuser/.gem/ruby/1.8/
    

    If you then run gem install it will pick up your gem and install it. Make sure you run the copy command as superuser (sudo, if you're running Ubuntu like me)

    P.S If, when you run $ gem environment, you get an "undefined method ‘manage_gems’ for Gem:Module (NoMethodError)" error, then edit /usr/bin/gem and ensure that the first three lines of the file look like this:

    1. require 'rubygems'
    2. require 'rubygems/gem_runner'
    3. Gem.manage_gems

    0 讨论(0)
  • 2021-01-30 21:34

    Just some more clarification in case you need to build / install your own gem file in this example foo-bar.

    gem build foo-bar.gemspec
    gem install --local foo-bar-0.1.0.gem
    

    I was researching how to do this and this post was first result :)

    0 讨论(0)
提交回复
热议问题