How to Install a Local Gem

How can I install a local gem?

Yup, when you do gem install, it will search the current directory first, so if your .gem file is there, it will pick it up. I found it on the gem reference, which you may find handy as well:

gem install will install the named
gem. It will attempt a local
installation (i.e. a .gem file in the
current directory), and if that fails,
it will attempt to download and
install the most recent version of the
gem you want.

Install gem in local folder

You can try:

gem install --user-install gem_name

Install a ruby gem from a local repository

In your local repository:

gem build yourlocalrepo.gemspec

This will create a .gem file.
Now:

gem install yourlocalrepo.gem

How can I specify a local gem in my Gemfile?

I believe you can do this:

gem "foo", path: "/path/to/foo"

Bundler: install local gem with system gems

No, Bundler treats path gems differently and does not install them to your GEM_PATH. This is so that you don't need to reinstall as you make changes.

It is not normal or necessary for a gem to point to itself or its runtime dependencies in its Gemfile. You might want to add gemspec to do this automatically. See http://bundler.io/v1.3/rubygems.html

How to reference a local gem from a ruby script?

Make sure that your gem name as same as in Gemfile (e.g. custom_gem)

# Gemfile

source "https://rubygems.org"

gem "custom_gem", path: "/home/username/path/to/custom_gem"

Don't forget to actually install this gem using bundler

bundle install

After that, the script should be ready to use by bundle exec ruby script.rb

# script.rb

require 'custom_gem'
CustomGem::Do.something

Couldn't install local gem

You don’t install the .gemspec file, you use that to build the gem, and then install the resulting gem.

Something like:

$ gem build mygem.gemspec
Successfully built RubyGem
Name: mygem
Version: 1.0.0
File: mygem-1.0.0.gem

and then:

$ gem install mygem-1.0.0.gem
Successfully installed mygem-1.0.0
1 gem installed

How do I specify local .gem files in my Gemfile?

This isn't strictly an answer to your question about installing .gem packages, but you can specify all kinds of locations on a gem-by-gem basis by editing your Gemfile.

Specifying a :path attribute will install the gem from that path on your local machine.

gem "foreman", path: "/Users/pje/my_foreman_fork"

Alternately, specifying a :git attribute will install the gem from a remote git repository.

gem "foreman", git: "git://github.com/pje/foreman.git"

# ...or at a specific SHA-1 ref
gem "foreman", git: "git://github.com/pje/foreman.git", ref: "bf648a070c"

# ...or branch
gem "foreman", git: "git://github.com/pje/foreman.git", branch: "jruby"

# ...or tag
gem "foreman", git: "git://github.com/pje/foreman.git", tag: "v0.45.0"

(As @JHurrah mentioned in his comment.)



Related Topics



Leave a reply



Submit