【问题标题】:Why does Passenger says that my gem 'json' can't be found, when my gem list shows it?当我的宝石列表显示时,为什么乘客说找不到我的宝石“json”?
【发布时间】:2014-01-31 09:56:24
【问题描述】:

我的 Apache 服务器上的 Ruby on Rails 的 phusion 乘客收到以下错误消息:

It looks like Bundler could not find a gem. This is probably because your
application is being run under a different environment than it's supposed to.
Please check the following:

 * Is this app supposed to be run as the `rvm_admin` user?
 * Is this app being run on the correct Ruby interpreter? Below you will
   see which Ruby interpreter Phusion Passenger attempted to use.
 * Are you using RVM? Please check whether the correct gemset is being used.
 * If all of the above fails, try resetting your RVM gemsets:
   https://github.com/phusion/passenger/wiki/Resetting-RVM-gemsets

-------- The exception is as follows: -------
Could not find json-1.8.1 in any of the sources (Bundler::GemNotFound)

这很奇怪,因为当我执行 gem list 命令时:

rvm_admin@myserver:~$ gem list

*** LOCAL GEMS ***

actionmailer (3.2.16)
actionpack (3.2.16)
activemodel (3.2.16)
activerecord (3.2.16)
activeresource (3.2.16)
activesupport (3.2.16)
annotate (2.6.1)
arel (3.0.3)
atomic (1.1.14)
bcrypt-ruby (3.1.2)
bigdecimal (1.2.3)
builder (3.0.4)
bundler (1.5.2)
capistrano (3.0.1)
chunky_png (1.2.9)
coffee-rails (3.2.1)
coffee-script (2.2.0)
coffee-script-source (1.7.0)
compass (0.12.2)
compass-rails (1.1.3)
declarative_authorization (0.5.7)
devise (3.2.2)
diff-lcs (1.2.5)
erubis (2.7.0)
execjs (2.0.2)
faker (1.2.0)
fssm (0.2.10)
haml (4.0.5)
haml-rails (0.4)
hike (1.2.3)
i18n (0.6.9)
io-console (0.4.2)
journey (1.0.4)
jquery-rails (3.1.0)
json (1.8.1)
libv8 (3.16.14.3 x86_64-linux)
mail (2.5.4)
mime-types (1.25.1)
minitest (4.7.5)
multi_json (1.8.4)
net-scp (1.1.2)
net-ssh (2.7.0)
orm_adapter (0.5.0)
pg (0.17.1)
polyamorous (0.6.4)
polyglot (0.3.3)
psych (2.0.2)
rack (1.4.5)
rack-cache (1.2)
rack-ssl (1.3.3)
rack-test (0.6.2)
rails (3.2.16)
rails-translate-routes (0.1.3)
railties (3.2.16)
rake (10.1.1, 10.1.0)
rdoc (4.1.0, 3.12.2)
ref (1.0.5)
role_model (0.8.1)
rspec-core (2.14.7)
rspec-expectations (2.14.4)
rspec-mocks (2.14.4)
rspec-rails (2.14.1)
ruby-ole (1.2.11.7)
sass (3.2.14)
sass-rails (3.2.6)
schema_plus (1.3.2)
spreadsheet (0.9.6)
sprockets (2.2.2)
squeel (1.1.1)
sshkit (1.0.0)
term-ansicolor (1.2.2)
test-unit (2.1.0.0)
therubyracer (0.12.0)
thor (0.18.1)
thread_safe (0.1.3)
tilt (1.4.1)
timeliness (0.3.7)
tins (0.13.1)
treetop (1.4.15)
tzinfo (0.3.38)
uglifier (2.4.0)
validates_timeliness (3.0.14)
valuable (0.9.8)
warden (1.2.3)

json 似乎在那里

但是如果我做一个

rvm_admin@myserver:~$ bundle show json
Could not locate Gemfile

为什么会这样?

这里是我的宝石集:

rvm_admin@myserver:~$ rvm gemset list

gemsets for ruby-2.1.0 (found in /usr/local/rvm/gems/ruby-2.1.0)
=> (default)
   global

所以除了全局的,没有其他 gemsets。

这是我的Gemfile:

source 'https://rubygems.org'
gem 'rails', '~>3.2'
gem 'pg', '>= 0.14'
gem 'haml-rails' , '>= 0.3'
gem 'execjs'
gem 'therubyracer', :platforms => :ruby

group :development, :test do
  gem 'factory_girl_rails'
end

group :developpement do
  gem 'rspec-rails', '~> 2.11'
  gem 'capistrano', '~> 3.0.1'
  gem 'faker', '>= 1.0'
  gem 'sshkit', '~> 1.0.0'
end

group :test do
  gem 'rspec', '>= 2.11'
  gem 'webrat', '>= 0.7'
  gem 'spork-rails', '>= 3.2'
end

group :assets do
  gem 'sass-rails',   '>= 3.2.3'
  gem 'coffee-rails', '>= 3.2.1'
  gem 'compass-rails', '>= 1.0'
  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'
gem 'annotate'
gem 'spreadsheet' #, '~> 0.7'
gem 'schema_plus' #, :git => "git://github.com/lomba/schema_plus.git"
gem 'squeel' #, '~> 1.0'
gem 'devise' #, '~> 2.1'
gem 'role_model'
gem 'declarative_authorization'
gem 'rails-translate-routes'  #, '~> 0.1'
gem 'validates_timeliness'  #, '~> 3.0'

我使用 bundle install --without developement test 命令手动安装 gems。 我不希望 Capistrano 执行任何类型的服务器包安装。所以我没有安装诸如 capistrano-rvm 或 capistrano-rails 之类的 gem。

怎么了?我该怎么办?

=== 编辑

如果我进入我的应用文件夹并检查 Json,它似乎存在:

rvm_admin@myserver:/var/www/odpf/current$ bundle show json
The gem json has been deleted. It was installed at:
/usr/local/rvm/rubies/ruby-2.1.0/lib/ruby/gems/2.1.0/gems/json-1.8.1

【问题讨论】:

  • 你试过在 Gemfile 中包含gem 'json' 吗? (修改Gemfile后再次运行bundle install)
  • 是的,我使用 bundle install --without development test 做到了这一点,但问题仍然存在。此外,如果我尝试从我的应用程序文件夹中卸载 json gem,它会说:无法卸载 gem "json",因为它是默认 gem

标签: ruby-on-rails-3.2 rvm passenger gemset


【解决方案1】:

我解决了这个问题。 问题来自 Phusion 乘客 ruby​​ 解释器字符串。

由于 Phusion 乘客不再是一个 gem,而是一个包,apt-get 将安装一个依赖包:一个旧版本的 ruby​​ 包

所以即使我用 RVM (ruby 2.1.0) 安装了一个单一版本的 ruby​​,Phusion Passenger 使用的是 /usr/bin/ruby 包中提供的那个 (1.9.3),因此,Passenger 不知何故在寻找将宝石放入此解释器文件夹。当然,他找不到所需的 gem,因为它们是根据 ruby​​ 2.1.0 而不是 ruby​​ 1.9.3 安装的。

执行rvm gemset list 命令将显示当前使用的gemset,但不幸的是,我们不能假设当我们安装gem 时它们会进入当前gemset。 它比这更复杂和模糊。您安装 gem 的文件夹位置似乎很重要。 此外,gem list 命令显示的 gem 对于解决 gem 问题几乎毫无用处。在服务器上安装 ruby​​ 环境真的很痛苦....

bundler web site 部署页面解释了这一点。我从来没有找到关于 rvm 和 bundler 如何管理 gem 的详细解释。

为了解决这个问题,我不得不执行以下命令

passenger-config --ruby-command

输出给了我“ruby解释器命令”复制并粘贴到我的 /etc/apache2/sites-available/mysite apache 配置文件:

PassengerRuby /usr/local/rvm/gems/ruby-2.1.0/wrappers/ruby

但是,我将它放在了PassengerDefaultRuby 参数内的配置文件的全局部分中,以确保所有ruby 帮助工具都使用这个版本并且只使用这个版本的ruby 2.1.0:

PassengerDefaultRuby /usr/local/rvm/gems/ruby-2.1.0/wrappers/ruby

有关如何设置 ruby​​ 解释器字符串的更多信息在“RVM 帮助工具”部分中的 here 中进行了说明。

强烈推荐阅读。

【讨论】:

  • 谢谢,这是一个很大的帮助——我在 rvm 全局 gemset 中安装乘客时遇到了类似的问题,但是我的 rails 应用程序从它自己的 gemset 运行。乘客似乎因此搜索了全球的一切
【解决方案2】:

我使用的是 ubuntu 14.04 和 nginx 并得到错误:

在任何源中都找不到 json-1.8.1 (Bundler::GemNotFound)

所以,我运行命令:

$ passenger-config --ruby-command

然后我将文件nginx.conf 中的变量:passenger_ruby 更改为“To use in Nginx”的值。效果很好。

【讨论】:

    猜你喜欢
    • 2012-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-15
    • 1970-01-01
    • 2016-03-17
    • 1970-01-01
    • 2019-08-09
    相关资源
    最近更新 更多