我無法弄清楚如何使用Apache承載我自己創建的Ruby寶石。我想知道是否有人能幫我弄清楚問題所在。使用Apache承載Ruby寶石
這是我到目前爲止已經完成。我開始通過創建自己的「Hello World」寶石(按照these instructions):
$ 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 = ["[email protected]"]
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 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」寶石(通過清空整個寶石),然後從服務器重新安裝:
$ rvm gemset empty currentgemset
Are you SURE you wish to remove the installed gems for gemset '[email protected]' (/home/joe/.rvm/gems/[email protected])?
(anything other than 'yes' will cancel) > yes
我需要設置Apache舉辦這種寶石。我在http://docs.rubygems.org/read/chapter/18#page81這樣做是按照指示:
$ 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是目前託管的寶石,我可以用我的網頁瀏覽器在本地主機/寶石成功訪問這個目錄。不過,我無法從Apache服務器安裝我的寶石:
$ 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/作爲寶石的來源,但沒有解決問題。有人告訴我將--legacy標誌添加到$ gem generate_index的調用中,但這也不起作用。
你配置了apache來從/ var/www/gems提供文件嗎? – 2013-04-04 16:33:12
@Frederick Cheung沒有明確說明,但這些文件的提供證明了我可以在我的網絡瀏覽器中看到它們,就像我在文章中提到的那樣 – user2245766 2013-04-04 16:35:55