postgresql Rails 启动时出现 Ruby/PgSQL 错误:无法加载此类文件 -- pg_ext (LoadError)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15147877/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 00:49:03  来源:igfitidea点击:

Ruby/PgSQL error on Rails start : cannot load such file -- pg_ext (LoadError)

ruby-on-railsrubypostgresql

提问by Mike Melusky

I'm new to Ruby (coming from a Java background) and was given access to a RoR project from a Git repository. I was able to get Ruby built with rbenv and Postgres installed via homebrew, installed the "pg" gem using the correct flags. Any ways I did "bundle install" on the project and it created a bundle, when I went to start the server:... any help will be definitely appreciated!

我是 Ruby 的新手(来自 Java 背景),并获得了从 Git 存储库访问 RoR 项目的权限。我能够使用 rbenv 构建 Ruby,并通过自制软件安装 Postgres,使用正确的标志安装了“pg” gem。我在项目上进行“捆绑安装”并创建了一个捆绑包的任何方式,当我去启动服务器时:...任何帮助都将不胜感激!

$ rails s
/Users//Projects/The /vendor/bundle/gems/pg-0.14.1/lib/pg.rb:4:in require': cannot load such file -- pg_ext (LoadError)

from /Users//Projects/The Usic/vendor/bundle/gems/pg-0.14.1/lib/pg.rb:4:in <top (required)>'

from /Users//.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/bundler-1.3.0/lib/bundler/runtime.rb:72:in require'

from /Users//.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/bundler-1.3.0/lib/bundler/runtime.rb:72:in block (2 levels) in require'

from /Users//.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/bundler-1.3.0/lib/bundler/runtime.rb:70:in each'

from /Users//.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/bundler-1.3.0/lib/bundler/runtime.rb:70:in block in require'

from /Users//.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/bundler-1.3.0/lib/bundler/runtime.rb:59:in each'

from /Users//.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/bundler-1.3.0/lib/bundler/runtime.rb:59:in require'

from /Users//.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/bundler-1.3.0/lib/bundler.rb:132:in require'

回答by Darkside

Issue also appears in Fedora 17.

Fedora 17 中也出现了问题。

Uninstall "pg" gem:

卸载“pg”gem:

gem uninstall pg

Run bundle (assuming Gemfile contains "pg" gem):

运行包(假设 Gemfile 包含“pg”gem):

bundle

回答by Mukesh

Add the pggem to your Gemfile. Then run:

pggem添加到您的Gemfile. 然后运行:

bundle install
bundle update

回答by principat

If during the installation of the gem the pq installation is not in path so it could not be found by the gem. Than the gem would not work correct.

如果在安装 gem 期间 pq 安装不在路径中,则 gem 无法找到它。比宝石不能正常工作。

  • Check the path (try to start psqlfrom commandline).
  • uninstall the pg-gem: gem unistall pg
  • and reinstall it: bundle installor gem install pg
  • 检查路径(尝试psql从命令行启动)。
  • 卸载 pg-gem: gem unistall pg
  • 并重新安装它:bundle installgem install pg

回答by Arman Ortega

I've already installed the pg gem list pg

我已经安装了 pg gem list pg

I also encountered this problem and I made it work. First, you run the command: $ gem install pg --pre
Successfully installed pg-0.21.0-x64-mingw32

我也遇到了这个问题,我让它工作了。首先,您运行命令: $ gem install pg --pre 已
成功安装 pg-0.21.0-x64-mingw32

Next, you update your Gemfile: gem 'pg', '~> 0.21.0'. That's it.

接下来,您更新您的 Gemfile: gem 'pg', '~> 0.21.0'。而已。

My rubygems environment are as follow:

我的rubygems环境如下:

RubyGems Environment:
  - RUBYGEMS VERSION: 2.6.12
  - RUBY VERSION: 2.3.3 (2016-11-21 patchlevel 222) [x64-mingw32]
  - INSTALLATION DIRECTORY: C:/Ruby23-x64/lib/ruby/gems/2.3.0
  - USER INSTALLATION DIRECTORY: C:/Users/armano/.gem/ruby/2.3.0
  - RUBY EXECUTABLE: C:/Ruby23-x64/bin/ruby.exe
  - EXECUTABLE DIRECTORY: C:/Ruby23-x64/bin
  - SPEC CACHE DIRECTORY: C:/Users/armano/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: C:/ProgramData
  - RUBYGEMS PLATFORMS:
    - ruby
    - x64-mingw32
  - GEM PATHS:
     - C:/Ruby23-x64/lib/ruby/gems/2.3.0
     - C:/Users/armano/.gem/ruby/2.3.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
     - "gem" => "--no-ri --no-rdoc"
  - REMOTE SOURCES:
     - https://rubygems.org/

回答by Mario Zigliotto

I'm curious if you installed the pg gem before or after installing postgres via brew?

我很好奇您是在通过 brew 安装 postgres 之前还是之后安装了 pg gem?

If pg was installed before you installed Postgres via brew, you may need to remove it and install it again so that it's compiled against your current version of Postgres.

如果在您通过 brew 安装 Postgres 之前安装了 pg,您可能需要删除它并重新安装它,以便它针对您当前的 Postgres 版本进行编译。

Side note: postgresapp is a much better alternative to installing postgres via homebrew: http://postgresapp.com/

旁注:postgresapp 是通过自制软件安装 postgres 的更好选择:http: //postgresapp.com/