POSTGRESQL无法构建gem原生扩展

时间:2015-12-04 00:02:04

标签: ruby-on-rails ruby macos postgresql gem

好的,当我尝试创建一个新的rails项目时遇到了这个问题, 但首先我会告诉你我已经设置了常见的问题(Ruby版,bundler,brew postgresql

~
▶ type rbenv
rbenv is a shell function

▶ gem list | grep bundler
bundler (1.10.6)

▶ rbenv local
rbenv: no local version configured for this directory

▶ which psql
/usr/local/bin/psql

▶ which bundler
/Users/hectorleon/.rbenv/shims/bundler

▶ which postgresql
postgresql not found

▶ which psql     
/usr/local/bin/psql
▶ brew list
autoconf    git     mpfr      openssl     python      readline    xz
boost     gmp     mysql     pcre      python3     redis     zsh
gcc     isl     node      pkg-config    rbenv     ruby-build    zsh-completions
gdbm      libmpc      numpy     postgresql    rbenv-gem-rehash  sqlite

▶ createuser myusername
createuser: creation of new role failed: ERROR:  role "myusername" already exists

▶ brew install postgresql
Warning: postgresql-9.4.5_2 already installed

▶ ruby -v
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]

▶ gem install pg
Building native extensions.  This could take a while...
Successfully installed pg-0.18.4
Parsing documentation for pg-0.18.4
Done installing documentation for pg after 2 seconds
1 gem installed

▶ brew list
autoconf    git     libpqxx     numpy     postgresql    rbenv-gem-rehash  sqlite
boost     gmp     mpfr      openssl     python      readline    xz
gcc     isl     mysql     pcre      python3     redis     zsh
gdbm      libmpc      node      pkg-config    rbenv     ruby-build    zsh-completions

好的,使用Homebrew和rbenv安装了一堆东西。现在让我们创建一个rails项目,看看会发生什么。

▶ rails new whygodwhy -d postgresql
      create  
      create  README.rdoc
      create  Rakefile
      create  config.ru
      create  .gitignore
      create  Gemfile
      create  app
      create  app/assets/javascripts/application.js
      create  app/assets/stylesheets/application.css
      create  app/controllers/application_controller.rb
      create  app/helpers/application_helper.rb
      create  app/views/layouts/application.html.erb
      create  app/assets/images/.keep
      create  app/mailers/.keep
      create  app/models/.keep
      create  app/controllers/concerns/.keep
      create  app/models/concerns/.keep
      create  bin
      create  bin/bundle
      create  bin/rails
      create  bin/rake
      create  bin/setup
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.rb
      create  config/secrets.yml
      create  config/environments
      create  config/environments/development.rb
      create  config/environments/production.rb
      create  config/environments/test.rb
      create  config/initializers
      create  config/initializers/assets.rb
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/cookies_serializer.rb
      create  config/initializers/filter_parameter_logging.rb
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/session_store.rb
      create  config/initializers/wrap_parameters.rb
      create  config/locales
      create  config/locales/en.yml
      create  config/boot.rb
      create  config/database.yml
      create  db
      create  db/seeds.rb
      create  lib
      create  lib/tasks
      create  lib/tasks/.keep
      create  lib/assets
      create  lib/assets/.keep
      create  log
      create  log/.keep
      create  public
      create  public/404.html
      create  public/422.html
      create  public/500.html
      create  public/favicon.ico
      create  public/robots.txt
      create  test/fixtures
      create  test/fixtures/.keep
      create  test/controllers
      create  test/controllers/.keep
      create  test/mailers
      create  test/mailers/.keep
      create  test/models
      create  test/models/.keep
      create  test/helpers
      create  test/helpers/.keep
      create  test/integration
      create  test/integration/.keep
      create  test/test_helper.rb
      create  tmp/cache
      create  tmp/cache/assets
      create  vendor/assets/javascripts
      create  vendor/assets/javascripts/.keep
      create  vendor/assets/stylesheets
      create  vendor/assets/stylesheets/.keep
         run  bundle install


Your user account isn't allowed to install to the system Rubygems.
You can cancel this installation and run:

    bundle install --path vendor/bundle

to install the gems into ./vendor/bundle/, or you can enter your password
and install the bundled gems to Rubygems using sudo.

Password: 
Fetching gem metadata from https://rubygems.org/............
Fetching version metadata from https://rubygems.org/...
Fetching dependency metadata from https://rubygems.org/..
Resolving dependencies....
Using rake 10.4.2
Using i18n 0.7.0
Using json 1.8.3
Using minitest 5.8.3
Using thread_safe 0.3.5
Using tzinfo 1.2.2
Using activesupport 4.2.5
Using builder 3.2.2
Using erubis 2.7.0
Using mini_portile2 2.0.0
Using nokogiri 1.6.7
Using rails-deprecated_sanitizer 1.0.3
Using rails-dom-testing 1.0.7
Using loofah 2.0.3
Using rails-html-sanitizer 1.0.2
Using actionview 4.2.5
Using rack 1.6.4
Using rack-test 0.6.3
Using actionpack 4.2.5
Using globalid 0.3.6
Using activejob 4.2.5
Using mime-types 2.99
Using mail 2.6.3
Using actionmailer 4.2.5
Using activemodel 4.2.5
Using arel 6.0.3
Using activerecord 4.2.5
Using debug_inspector 0.0.2
Using binding_of_caller 0.7.2
Using bundler 1.10.6
Using byebug 8.2.1
Using coffee-script-source 1.10.0
Using execjs 2.6.0
Using coffee-script 2.4.1
Using thor 0.19.1
Using railties 4.2.5
Using coffee-rails 4.1.0
Using concurrent-ruby 1.0.0
Using multi_json 1.11.2
Using jbuilder 2.3.2
Using jquery-rails 4.0.5
Installing pg 0.18.4 with native extensions

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/local/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
  --with-opt-dir
  --without-opt-dir
  --with-opt-include
  --without-opt-include=${opt-dir}/include
  --with-opt-lib
  --without-opt-lib=${opt-dir}/lib
  --with-make-prog
  --without-make-prog
  --srcdir=.
  --curdir
  --ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
  --with-pg
  --without-pg
  --enable-windows-cross
  --disable-windows-cross
  --with-pg-config
  --without-pg-config
  --with-pg_config
  --without-pg_config
  --with-pg-dir
  --without-pg-dir
  --with-pg-include
  --without-pg-include=${pg-dir}/include
  --with-pg-lib
  --without-pg-lib=${pg-dir}/
  --with-pqlib
  --without-pqlib
  --with-libpqlib
  --without-libpqlib
  --with-ms/libpqlib
  --without-ms/libpqlib


Gem files will remain installed in /var/folders/m0/v30d40yd31bc5hf1lqrt5zn00000gn/T/bundler20151205-52465-pssww8pg-0.18.4/gems/pg-0.18.4 for inspection.
Results logged to /var/folders/m0/v30d40yd31bc5hf1lqrt5zn00000gn/T/bundler20151205-52465-pssww8pg-0.18.4/gems/pg-0.18.4/ext/gem_make.out
An error occurred while installing pg (0.18.4), and Bundler cannot continue.
Make sure that `gem install pg -v '0.18.4'` succeeds before bundling.
         run  bundle exec spring binstub --all
/Library/Ruby/Gems/2.0.0/gems/bundler-1.10.6/lib/bundler/resolver.rb:347:in `block in verify_gemfile_dependencies_are_found!': Could not find gem 'rails (= 4.2.5) ruby' in any of the gem sources listed in your Gemfile or available on this machine. (Bundler::GemNotFound)
  from /Library/Ruby/Gems/2.0.0/gems/bundler-1.10.6/lib/bundler/resolver.rb:325:in `each'
  from /Library/Ruby/Gems/2.0.0/gems/bundler-1.10.6/lib/bundler/resolver.rb:325:in `verify_gemfile_dependencies_are_found!'
  from /Library/Ruby/Gems/2.0.0/gems/bundler-1.10.6/lib/bundler/resolver.rb:198:in `start'
  from /Library/Ruby/Gems/2.0.0/gems/bundler-1.10.6/lib/bundler/resolver.rb:182:in `resolve'
  from /Library/Ruby/Gems/2.0.0/gems/bundler-1.10.6/lib/bundler/definition.rb:200:in `resolve'
  from /Library/Ruby/Gems/2.0.0/gems/bundler-1.10.6/lib/bundler/definition.rb:140:in `specs'
  from /Library/Ruby/Gems/2.0.0/gems/bundler-1.10.6/lib/bundler/definition.rb:185:in `specs_for'
  from /Library/Ruby/Gems/2.0.0/gems/bundler-1.10.6/lib/bundler/definition.rb:174:in `requested_specs'
  from /Library/Ruby/Gems/2.0.0/gems/bundler-1.10.6/lib/bundler/environment.rb:18:in `requested_specs'
  from /Library/Ruby/Gems/2.0.0/gems/bundler-1.10.6/lib/bundler/runtime.rb:13:in `setup'
  from /Library/Ruby/Gems/2.0.0/gems/bundler-1.10.6/lib/bundler.rb:127:in `setup'
  from /Library/Ruby/Gems/2.0.0/gems/bundler-1.10.6/lib/bundler/setup.rb:18:in `<top (required)>'
  from /Users/myusername/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
  from /Users/myusername/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'

好的......所以我看到说“找不到PostgreSQL客户端库(libpq)” 怎么安装呢?不知道,谷歌没有发现任何东西。

另外如果我尝试在postgresql文件夹里面得到这条消息

postgres does not know where to find the server configuration file. You must specify the --config-file or -D invocation option or set the PGDATA environment variable

汇总:

  • 我成功安装了pg gem(原生扩展成功创建)但之后,rails项目说我无法构建原生扩展。
  • 当我安装了捆绑包并且rbenv很好时,我需要密码来安装宝石:没有意义
  • 我没有libpq,我不知道我需要的方式/位置或命令:S
  • 我安装了postgresql但没有安装服务器配置文件
  • 我会死哈哈,没有人会认真帮助我吗?我在两天内浪费了5个小时试图解决这个问题,笔记本电脑是新的,安装了OSXELCapitán。

1 个答案:

答案 0 :(得分:0)

  

找不到PostgreSQL客户端库(libpq)

您缺少名为 libpq 的库。安装后,请查看错误消息的更改方式,并在必要时重复此过程。

可能是这个库的名称略有不同,比如 libpq5 ,所以如果你没有找到100%匹配,你可能想尝试一下。

相关问题