Nginx 重启后 Rails 错误 "could nof find pg-0.18.3 in any of the sources"

Rails error "could nof find pg-0.18.3 in any of the sources" after Nginx restart

我正在尝试在 Nginx 上设置 Rails 4.2 一段时间。每次我开始使用 RVM 进行全新安装时,一切都会好起来的。我可以 运行 rake db:create:all 并创建数据库。但是,如果我使用 /etc/init.d/nginx restart 重新启动 Nginx,Passenger 会向我发送有关 gem :

的错误
It looks like Bundler could not find a gem. Maybe you didn't install all the gems that this application needs. To install your gems, please run:

bundle install

If that didn't work, then the problem is probably caused by your application being run under a different environment than it's supposed to. Please check the following:

    Is this app supposed to be run as the www-data user?
    Is this app being run on the correct Ruby interpreter? Below you will see which Ruby interpreter Phusion Passenger attempted to use.

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

  /var/lib/gems/2.1.0/gems/bundler-1.10.6/lib/bundler/spec_set.rb:92:in `block in materialize'
  /var/lib/gems/2.1.0/gems/bundler-1.10.6/lib/bundler/spec_set.rb:85:in `map!'
  /var/lib/gems/2.1.0/gems/bundler-1.10.6/lib/bundler/spec_set.rb:85:in `materialize'
  /var/lib/gems/2.1.0/gems/bundler-1.10.6/lib/bundler/definition.rb:140:in `specs'
  /var/lib/gems/2.1.0/gems/bundler-1.10.6/lib/bundler/definition.rb:185:in `specs_for'
  /var/lib/gems/2.1.0/gems/bundler-1.10.6/lib/bundler/definition.rb:174:in `requested_specs'
  /var/lib/gems/2.1.0/gems/bundler-1.10.6/lib/bundler/environment.rb:18:in `requested_specs'
  /var/lib/gems/2.1.0/gems/bundler-1.10.6/lib/bundler/runtime.rb:13:in `setup'
  /var/lib/gems/2.1.0/gems/bundler-1.10.6/lib/bundler.rb:127:in `setup'
  /var/lib/gems/2.1.0/gems/bundler-1.10.6/lib/bundler/setup.rb:18:in `<top (required)>'
  /usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
  /usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
  /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:411:in `activate_gem'
  /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:295:in `block in run_load_path_setup_code'
  /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:416:in `running_bundler'
  /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:294:in `run_load_path_setup_code'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:99:in `preload_app'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:153:in `<module:App>'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `<module:PhusionPassenger>'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:28:in `<main>'

pg gem 已经安装在我的 Gemfile 和 RVM 中:

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.4'

gem 'pg', '~> 0.18.3'

gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'therubyracer', platforms: :ruby

gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

gem 'execjs'

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'

  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
end

然后如果我 运行 gem query --local 我得到 pg (0.18.3)

config/database.yml :

login: &login
  adapter: postgresql
  username: myuser
  password: mypass
  host: localhost
  encoding: UTF8

development:
  <<: *login
  database: mydb_dev

test:
  <<: *login
  database: mydb_test

production:
  <<: *login
  database: mydb_prod

rvm 信息:

  ruby:
    interpreter:  "ruby"
    version:      "2.2.1p85"
    date:         "2015-02-26"
    platform:     "x86_64-linux"
    patchlevel:   "2015-02-26 revision 49769"
    full_version: "ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-linux]"

  homes:
    gem:          "/usr/local/rvm/gems/ruby-2.2.1"
    ruby:         "/usr/local/rvm/rubies/ruby-2.2.1"

  binaries:
    ruby:         "/usr/local/rvm/rubies/ruby-2.2.1/bin/ruby"
    irb:          "/usr/local/rvm/rubies/ruby-2.2.1/bin/irb"
    gem:          "/usr/local/rvm/rubies/ruby-2.2.1/bin/gem"
    rake:         "/usr/local/rvm/rubies/ruby-2.2.1/bin/rake"

  environment:
    PATH:         "/usr/local/rvm/gems/ruby-2.2.1/bin:/usr/local/rvm/gems/ruby-2.2.1@global/bin:/usr/local/rvm/rubies/ruby-2.2.1/bin:/usr/local/rvm/bin:/root/.composer/vendor/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
    GEM_HOME:     "/usr/local/rvm/gems/ruby-2.2.1"
    GEM_PATH:     "/usr/local/rvm/gems/ruby-2.2.1:/usr/local/rvm/gems/ruby-2.2.1@global"
    MY_RUBY_HOME: "/usr/local/rvm/rubies/ruby-2.2.1"
    IRBRC:        "/usr/local/rvm/rubies/ruby-2.2.1/.irbrc"
    RUBYOPT:      ""

我尝试重启 Nginx 时是否做错了什么?

您似乎安装了 gem,但您的捆绑器在您重新启动时找不到它。

一些想法:

  • 您是否在 gem 文件目录中执行了捆绑?尝试 运行 bundle exec gem list 查看您的包中实际包含的内容,而不仅仅是本地安装的内容(这是您在 gem query --local 中看到的内容)。
  • 检查您是否有一个由 rvm 设置的默认版本 ruby 与捆绑的内容相匹配。有可能,当您重新启动时,它默认为错误的 Ruby 版本(然后查找错误的路径)