如何在Gemfile中指定本地.gem文件?

时间:2023-01-13 10:03:54

I have a couple of gem files which I install via gem install xx.gem. Can I tell Bundler to use them? Or do I have to specify the source path?

我有几个gem文件,我通过gem安装xxx .gem来安装它们。我能告诉Bundler使用它们吗?还是必须指定源路径?

6 个解决方案

#1


24  

By default Bundler will check your system first and if it can't find a gem it will use the sources specified in your Gemfile.

默认情况下,Bundler将首先检查系统,如果找不到gem,它将使用Gemfile中指定的源文件。

#2


236  

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.

严格来说,这并不是您关于安装.gem包的问题的答案,但是您可以通过编辑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.)

(正如@JHurrah在他的评论中提到的那样。)

#3


52  

Seems bundler can't use .gem files out of the box. Pointing the :path to a directory containing .gem files doesn't work. Some people suggested to setup a local gem server (geminabox, stickler) for that purpose.

看起来bundler不能使用。gem文件。指向包含.gem文件的目录的:路径不起作用。一些人建议为此设置一个本地gem服务器(geminabox, stickler)。

However, what I found to be much simpler is to use a local gem "server" from file system: Just put your .gem files in a local directory, then use "gem generate_index" to make it a Gem repository

但是,我发现更简单的方法是使用文件系统中的本地gem“server”:将.gem文件放在本地目录中,然后使用“gem generate_index”使其成为gem存储库

mkdir repo
mkdir repo/gems
cp *.gem repo/gems
cd repo
gem generate_index

Finally point bundler to this location by adding the following line to your Gemfile

最后,通过在您的Gemfile中添加以下行来将bundler指向这个位置。

source "file://path/to/repo"

If you update the gems in the repository, make sure to regenerate the index.

如果更新存储库中的gem,请确保重新生成索引。

#4


36  

I would unpack your gem in the application vendor folder

我将在application vendor文件夹中打开您的gem

gem unpack your.gem --target /path_to_app/vendor/gems/

Then add the path on the Gemfile to link unpacked gem.

然后在Gemfile上添加链接未打包的gem的路径。

gem 'your', '2.0.1', :path => 'vendor/gems/your'

#5


4  

You can force bundler to use the gems you deploy using "bundle package" and "bundle install --local"

您可以强制bundler使用“bundle package”和“bundle install——local”部署的gem

On your development machine:

在您的开发机:

bundle install

(Installs required gems and makes Gemfile.lock)

(安装所需的宝石并制作Gemfile.lock)

bundle package

(Caches the gems in vendor/cache)

(在供应商/缓存中缓存gem)

On the server:

在服务器上:

bundle install --local

(--local means "use the gems from vendor/cache")

(本地的意思是“从供应商/缓存中使用宝石”)

#6


0  

I found it easiest to run my own gem server using geminabox

我发现使用geminabox运行自己的gem服务器是最简单的

See these simple instructions.

看到这些简单的指令。

#1


24  

By default Bundler will check your system first and if it can't find a gem it will use the sources specified in your Gemfile.

默认情况下,Bundler将首先检查系统,如果找不到gem,它将使用Gemfile中指定的源文件。

#2


236  

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.

严格来说,这并不是您关于安装.gem包的问题的答案,但是您可以通过编辑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.)

(正如@JHurrah在他的评论中提到的那样。)

#3


52  

Seems bundler can't use .gem files out of the box. Pointing the :path to a directory containing .gem files doesn't work. Some people suggested to setup a local gem server (geminabox, stickler) for that purpose.

看起来bundler不能使用。gem文件。指向包含.gem文件的目录的:路径不起作用。一些人建议为此设置一个本地gem服务器(geminabox, stickler)。

However, what I found to be much simpler is to use a local gem "server" from file system: Just put your .gem files in a local directory, then use "gem generate_index" to make it a Gem repository

但是,我发现更简单的方法是使用文件系统中的本地gem“server”:将.gem文件放在本地目录中,然后使用“gem generate_index”使其成为gem存储库

mkdir repo
mkdir repo/gems
cp *.gem repo/gems
cd repo
gem generate_index

Finally point bundler to this location by adding the following line to your Gemfile

最后,通过在您的Gemfile中添加以下行来将bundler指向这个位置。

source "file://path/to/repo"

If you update the gems in the repository, make sure to regenerate the index.

如果更新存储库中的gem,请确保重新生成索引。

#4


36  

I would unpack your gem in the application vendor folder

我将在application vendor文件夹中打开您的gem

gem unpack your.gem --target /path_to_app/vendor/gems/

Then add the path on the Gemfile to link unpacked gem.

然后在Gemfile上添加链接未打包的gem的路径。

gem 'your', '2.0.1', :path => 'vendor/gems/your'

#5


4  

You can force bundler to use the gems you deploy using "bundle package" and "bundle install --local"

您可以强制bundler使用“bundle package”和“bundle install——local”部署的gem

On your development machine:

在您的开发机:

bundle install

(Installs required gems and makes Gemfile.lock)

(安装所需的宝石并制作Gemfile.lock)

bundle package

(Caches the gems in vendor/cache)

(在供应商/缓存中缓存gem)

On the server:

在服务器上:

bundle install --local

(--local means "use the gems from vendor/cache")

(本地的意思是“从供应商/缓存中使用宝石”)

#6


0  

I found it easiest to run my own gem server using geminabox

我发现使用geminabox运行自己的gem服务器是最简单的

See these simple instructions.

看到这些简单的指令。