【发布时间】:2011-02-04 08:41:12
【问题描述】:
我想从最新的 GitHub 源安装 gem。
我该怎么做?
【问题讨论】:
标签: rubygems
我想从最新的 GitHub 源安装 gem。
我该怎么做?
【问题讨论】:
标签: rubygems
嗯,这取决于所讨论的项目。一些项目的根目录中有一个 *.gemspec 文件。在这种情况下,它会是
gem build GEMNAME.gemspec
gem install gemname-version.gem
其他项目有一个 rake 任务,称为“gem”或“build”或类似的东西,在这种情况下您必须调用“rake”,但这取决于项目。
在这两种情况下,您都必须下载源代码。
【讨论】:
gem build时会创建gemname-version.gem文件
gem install gemname-version.gem 命令在哪里安装 git gem 本地?我在本地机器上的任何地方都找不到以这种方式安装的引擎 gem。 bundler 把它藏在哪里了?
gem install gemname-version.gem 行应该是gem install --local gemname-version.gem
gem which gemname 应该告诉你一个特定的宝石在哪里,这对你不起作用吗?
如果您使用的是 bundler,您需要在 Gemfile 中添加类似的内容:
gem 'redcarpet', :git => 'git://github.com/tanoku/redcarpet.git'
如果有.gemspec文件,它应该能够在运行bundle install时获取并安装gem。
UPD. 如 cmets 中所示,要使 Bundler 正常运行,您还需要将以下内容添加到 config.ru:
require "bundler"
Bundler.setup(:default)
【讨论】:
require "bundler" Bundler.setup(:default) 有关详细信息,请参阅 bundler docs
gem 'redcarpet', :git => 'git://github.com/tanoku/redcarpet.git', :branch => 'yourbranch'
gem 'redcarpet', github: 'tanoku/redcarpet'。 akash.im/2012/06/05/bundler-new-github-option.html
gem 'redcarpet', :git => 'git://github.com/tanoku/redcarpet.git', :tag => 'v2.3.5' :tag => '' 部分
试试specific_install gem,它允许您从其 github 存储库(如“edge”)或任意 URL 安装 gem。对于在多台机器上分叉宝石和对它们进行黑客攻击非常有用。
gem install specific_install
gem specific_install -l <url to a github gem>
例如
gem specific_install https://github.com/githubsvnclone/rdoc.git
【讨论】:
specific_install gem 上添加更多解释?
ERROR: While executing gem ... (NoMethodError) undefined method 'build' for Gem::Package:Module 听起来很酷,但我不会进一步研究它。只是想发布它对我不起作用,以防其他人将根据 SO 推荐试一试。
Bundler 允许您直接从 git 存储库中使用 gem。 在您的 Gemfile 中:
# Use the http(s), ssh, or git protocol
gem 'foo', git: 'https://github.com/dideler/foo.git'
gem 'foo', git: 'git@github.com:dideler/foo.git'
gem 'foo', git: 'git://github.com/dideler/foo.git'
# Specify a tag, ref, or branch to use
gem 'foo', git: 'git@github.com:dideler/foo.git', tag: 'v2.1.0'
gem 'foo', git: 'git@github.com:dideler/foo.git', ref: '4aded'
gem 'foo', git: 'git@github.com:dideler/foo.git', branch: 'development'
# Shorthand for public repos on GitHub (supports all the :git options)
gem 'foo', github: 'dideler/foo'
欲了解更多信息,请参阅https://bundler.io/v2.0/guides/git.html
【讨论】:
bundle 时,这样的 git-gem- 依赖项不会被全局安装,而是在当前用户的主目录中。乘客将以您的网络服务器用户(例如www-data)运行 ruby,该用户无权访问此目录,因此不会加载此“git-gem”。你会得到一个错误... is not yet checked out. Run bundle install first。
已过时(参见 cmets)
如果项目来自 github,并且包含在 http://gems.github.com/list.html 的列表中,那么您只需将 github 存储库添加到 gems 源即可安装它:
$ gem sources -a http://gems.github.com
$ sudo gem install username-projectname
【讨论】:
如果您从公共 GitHub 存储库获取 gem,可以使用简写
gem 'nokogiri', github: 'tenderlove/nokogiri'
【讨论】:
你也可以gem install username-projectname -s http://gems.github.com
【讨论】:
在您的 Gemfile 中,添加以下内容:
gem 'example', :git => 'git://github.com/example.git'
你还可以添加 ref、branch 和 tag 选项,
例如,如果您想从特定分支下载:
gem 'example', :git => "git://github.com/example.git", :branch => "my-branch"
然后运行:
bundle install
【讨论】:
如果您按照 gryzzly 的建议使用 bundler 进行安装,并且 gem 会创建一个二进制文件,那么请确保您使用 bundle exec mygembinary 运行它,因为 gem 存储在 bundler 目录中,该目录在普通 gem 路径中不可见。
【讨论】:
你也可以使用rdp/specific_installgem:
gem install specific_install
gem specific_install https://github.com/capistrano/drupal-deploy.git
【讨论】:
在新的 Linux 机器上,您还需要安装 git。 Bundle 在幕后使用它。
【讨论】: