【发布时间】:2017-01-12 19:25:58
【问题描述】:
在问题结束时更新了解决方案
我一直在兜圈子,试图解决我的 pg gem & rails 服务器的问题。我已经概述了我发现自己陷入的无限循环。您能否提供一些指导?
当我尝试启动我的 rails 服务器时,我收到以下错误消息:
Could not find gem 'pg (>= 0) ruby' in any of the gem sources listed in your Gemfile or available on this machine.
Run `bundle install` to install missing gems.
之后,我运行bundle install 并收到以下消息:
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/3l/gxc7bb4x0nb6b7n7039jl49r0000gn/T/bundler20170112-83505-1jpf7s0pg-0.19.0/gems/pg-0.19.0 for inspection.
Results logged to /var/folders/3l/gxc7bb4x0nb6b7n7039jl49r0000gn/T/bundler20170112-83505-1jpf7s0pg-0.19.0/gems/pg-0.19.0/ext/gem_make.out
An error occurred while installing pg (0.19.0), and Bundler cannot continue.
Make sure that `gem install pg -v '0.19.0'` succeeds before bundling.
接下来我运行 gem install pg -v '0.19.0' 并收到以下错误消息:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
然后我尝试运行 sudo gem install pg -v '0.19.0' 并收到以下错误消息:
ERROR: Error installing pg:
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 /Library/Ruby/Gems/2.0.0/gems/pg-0.19.0 for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/gems/pg-0.19.0/ext/gem_make.out
如果有帮助,我还运行了 rbenv versions,它显示:
system
* 2.1.0 (set by /Users/{user}/.rbenv/version)
我还尝试完全卸载 postgres,然后使用本指南重新安装:https://www.moncefbelyamani.com/how-to-install-postgresql-on-a-mac-with-homebrew-and-lunchy/
我该去哪里?
【问题讨论】:
-
你的电脑上是否安装了 postgresql(服务器或客户端)?
-
是的,我在此之前运行了
brew update和brew install postgresql。我会更新帖子。 -
ARCHFLAGS='-arch x86_64' gem install pg有区别吗? -
看起来不像:
ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory. -
嗯,您似乎没有在 rbenv 下运行,因为它正在尝试安装在系统 ruby 上,因此您可能会遇到多个问题。
标签: ruby-on-rails macos postgresql rubygems pg