首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Apache托管Ruby gem

使用Apache托管Ruby gem
EN

Stack Overflow用户
提问于 2013-04-05 00:30:18
回答 1查看 1.5K关注 0票数 2

我在想如何使用Apache托管我自己创建的Ruby gem时遇到了麻烦。我想知道有没有人能帮我解决这个问题。

以下是我到目前为止所做的工作。我首先创建了自己的"hello world“gem (通过遵循these instructions):

代码语言:javascript
复制
$ bundle gem helloearth

$ cat lib/helloearth.rb
require "helloearth/version"

module Helloearth
  def self.hi
    puts "hello world"
  end
end

$ cat helloearth.gemspec 
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'helloearth/version'

Gem::Specification.new do |spec|
  spec.name          = "helloearth"
  spec.version       = Helloearth::VERSION
  spec.authors       = ["Some Guy"]
  spec.email         = ["someguy@example.com"]
  spec.description   = %q{a gem description}
  spec.summary       = %q{a gem summary}
  spec.homepage      = "http://www.example.com"
  spec.license       = "MIT"

  spec.files         = `git ls-files`.split($/)
  spec.executables   = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
  spec.test_files    = spec.files.grep(%r{^(test|spec|features)/})
  spec.require_paths = ["lib"]

  spec.add_development_dependency "bundler", "~> 1.3"
  spec.add_development_dependency "rake"
end

然后,我构建了gem,安装并运行它,以验证它是否正常工作:

代码语言:javascript
复制
$ gem build helloearth.gemspec
  Successfully built RubyGem
  Name: helloearth
  Version: 0.0.1
  File: helloearth-0.0.1.gem

$ gem install ./helloearth-0.0.1.gem 
Successfully installed helloearth-0.0.1
1 gem installed
Installing ri documentation for helloearth-0.0.1...
Installing RDoc documentation for helloearth-0.0.1...

$ irb
1.9.3-p362 :001 > require 'helloearth'
 => true 
1.9.3-p362 :002 > Helloearth.hi
hello world
 => nil

它起作用了!现在我要卸载我的"hello world“gem (通过清空整个gemset),然后从服务器重新安装它:

代码语言:javascript
复制
$ rvm gemset empty currentgemset
Are you SURE you wish to remove the installed gems for gemset 'ruby-1.9.3-p362@currentgemset' (/home/joe/.rvm/gems/ruby-1.9.3-p362@currentgemset)?
(anything other than 'yes' will cancel) > yes

我需要设置Apache来托管这个gem。我按照http://docs.rubygems.org/read/chapter/18#page81上的说明做了这件事

代码语言:javascript
复制
$ sudo mkdir /var/www/gems
$ sudo cp helloearth-0.0.1.gem /var/www/gems
$ rvmsudo gem generate_index -d /var/www/gems/
Warning: can not check `/etc/sudoers` for `secure_path`, falling back to call via `/usr/bin/env`, this breaks rules from `/etc/sudoers`. export rvmsudo_secure_path=1 to avoid the warning.Generating Marshal quick index gemspecs for 0 gems

Complete
Generated Marshal quick index gemspecs: 0.000s
Generating Marshal master index
Generated Marshal master index: 0.000s
Generating specs index
Generated specs index: 0.000s
Generating latest specs index
Generated latest specs index: 0.000s
Generating prerelease specs index
Generated prerelease specs index: 0.000s
Compressing indicies
Compressed indicies: 0.001s

$ ls /var/www/gems
helloearth-0.0.1.gem  Marshal.4.8.Z            specs.4.8
latest_specs.4.8      prerelease_specs.4.8     specs.4.8.gz
latest_specs.4.8.gz   prerelease_specs.4.8.gz
Marshal.4.8           quick

Apache现在托管gem,我可以使用位于localhost/gems的web浏览器成功访问此目录。但是,我无法从Apache服务器安装我的gem:

代码语言:javascript
复制
$ gem sources -a http://localhost/gems/
http://localhost/gems/ added to sources

$ gem sources
*** CURRENT SOURCES ***

http://rubygems.org/
http://localhost/gems/

cd ~ # leave the directory which holds the local copy of the gem to force use of the Apache server

$ gem install helloearth
ERROR:  Could not find a valid gem 'helloearth' (>= 0) in any repository
ERROR:  Possible alternatives: hello_bar, hello_ext, hellogr, helloh, hellolorem

我还尝试添加127.0.0.1/gems/和0.0.0.0/gems/作为gem源代码,但都不能解决问题。有人告诉我在对$ gem generate_index的调用中添加--legacy标志,但这也不起作用。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-09 04:34:41

对于gem generate_index,helloearth-0.0.1.gem不在正确的位置。

如果希望源文件为/gems,则.gem文件需要位于/var/www/gems/gems中

gem generate_index -d调用位于父目录(BASEDIR)上,.gem文件位于/gems子目录中。

http://docs.rubygems.org/read/chapter/18 "How do I run a Gem Server like RubyForge?"

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15816725

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档