Jas*_*ett 146 postgresql rubygems ruby-on-rails ruby-on-rails-3
我正在尝试在Mac OS X 10.6上安装PostgreSQL for Rails.首先我尝试了MacPorts安装,但是进展不顺利,所以我做了一键式DMG安装.这似乎有效.
我怀疑我需要安装PostgreSQL开发包,但我不知道如何在OS X上执行此操作.
这是我尝试做的事情sudo gem install pg:
$ sudo gem install pg
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /Library/PostgreSQL/8.3/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.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/1.8/usr/bin/ruby
--with-pg
--without-pg
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
--with-pqlib
--without-pqlib
--with-libpqlib
--without-libpqlib
--with-ms/libpqlib
--without-ms/libpqlib
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/pg-0.11.0 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/pg-0.11.0/ext/gem_make.out
Run Code Online (Sandbox Code Playgroud)
小智 346
$ sudo su
$ env ARCHFLAGS="-arch x86_64" gem install pg
Building native extensions. This could take a while...
Successfully installed pg-0.11.0
1 gem installed
Installing ri documentation for pg-0.11.0...
Installing RDoc documentation for pg-0.11.0...
Run Code Online (Sandbox Code Playgroud)
成功了!
小智 78
我在这里尝试了最受欢迎的答案:
env ARCHFLAGS="-arch x86_64" gem install pg
Run Code Online (Sandbox Code Playgroud)
但是当我再次尝试运行bundle install时,它也有同样的错误.然后我用ARCHFLAGS尝试了整个bundle安装,如下所示:
ARCHFLAGS="-arch x86_64" bundle install
Run Code Online (Sandbox Code Playgroud)
为我工作!确保将x86_64替换为i386,具体取决于您拥有的架构.
eik*_*kes 34
错误消息就在那里:
Can't find the PostgreSQL client library (libpq)
Run Code Online (Sandbox Code Playgroud)
您可以通过使用自制程序来安装它来解决这个问题
brew install libpq
Run Code Online (Sandbox Code Playgroud)
将出现以下或类似消息:
If you need to have libpq first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/libpq/bin:$PATH"' >> ~/.zshrc
For compilers to find libpq you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/libpq/lib"
export CPPFLAGS="-I/opt/homebrew/opt/libpq/include"
Run Code Online (Sandbox Code Playgroud)
然后你可以运行它:
export PATH="/opt/homebrew/opt/libpq/bin:$PATH"
gem install pg
Run Code Online (Sandbox Code Playgroud)
完毕。
bob*_*et1 31
我在使用EnterpiseDB .dmg时遇到了这个问题.如果您认为这是相同的,我通过指定正确的架构来实现它:
sudo env ARCHFLAGS="-arch i386" gem install pg
Run Code Online (Sandbox Code Playgroud)
网上有一些教程说要指定一个不同的架构(比如使用MacPorts的人使用"-arch x86_64"),但是因为我使用了单个文件安装,所以它不适用于我.
etu*_*usm 24
如果使用优胜美地:
brew install postgres
Run Code Online (Sandbox Code Playgroud)
然后:
ARCHFLAGS="-arch x86_64" gem install pg
Run Code Online (Sandbox Code Playgroud)
和(可选)最后,如果你想发动autovacuum ...
postgres -D /usr/local/var/postgres
Run Code Online (Sandbox Code Playgroud)
yba*_*art 21
也许你可以尝试这个:
ARCHFLAGS="-arch i386 -arch x86_64" gem install pg
Run Code Online (Sandbox Code Playgroud)
要了解库的架构,您可以使用
file /usr/local/lib/libpq.dylib
Run Code Online (Sandbox Code Playgroud)
在我的情况下只提供了一个架构(通过自制软件安装):
/usr/local/lib/libpq.dylib: Mach-O 64-bit dynamically linked shared library x86_64
Run Code Online (Sandbox Code Playgroud)
Abh*_*bhi 19
如果您在 Mac M1 pro、硅芯片中遇到此错误
问题:
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)
Run Code Online (Sandbox Code Playgroud)
解决方案:
通过 homebrew 安装 libpq 并将其添加到 PATH
brew install libpq
echo 'export PATH="/opt/homebrew/opt/libpq/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
OR ~/bash_profile if you use it instead.
Run Code Online (Sandbox Code Playgroud)
尝试:
bundle install # OR
gem install pg
Run Code Online (Sandbox Code Playgroud)
这对我有用。
Léo*_*uez 16
大多数答案都集中在为您提供一个有效的命令。然而它们只适用于某些特定的场景。如果您无法确定应该运行哪个命令,您可以更好地了解发生了什么。
gempg是用 C 编写的本机扩展。它依赖于libpq用于 C 应用程序的 PostgreSQL 库。
因此,在构建过程中,pggem 需要能够找到libqp为相同架构编译的库(例如x86_64或arm64)。
如果出现以下情况,则可能会出现不匹配:
postgres为 Rosetta 2 模式。postgres以 32 位模式安装。如果您最终遇到这种情况,您有多种选择:
pg在相同的架构中编译 gempostgresgem(默认情况下与 的相同ruby)例如,就我而言,我有一台 m1 MacBook。我已经在“rosetta 2”模式下安装了 ruby ( x86_64),在“本机”模式下安装了 postgres ( arm64)。
您可以使用以下命令检查架构lipo -info:
which ruby
# You might need to use a different command if you use a ruby version manager
# "which ruby" if you use rvm
# "rbenv which ruby" if you use rbenv
# "asdf which ruby" if you use asdf
=> /Users/leo/.rbenv/versions/2.6.6/bin/ruby
lipo -info /Users/leo/.rbenv/versions/2.6.6/bin/ruby
=> /Users/leo/.rbenv/versions/2.6.6/bin/ruby is architecture: x86_64
Run Code Online (Sandbox Code Playgroud)
which postgres
=> /opt/homebrew/bin/pg_config
lipo -info /opt/homebrew/bin/pg_config
=> Non-fat file: /opt/homebrew/bin/pg_config is architecture: arm64
Run Code Online (Sandbox Code Playgroud)
为了解决这个问题,就我而言,我只需添加到另一个编译PATH版本中。它使gem 能够找到正确架构中的二进制文件:postgresx86_64pg
export PATH=/usr/local/Cellar/postgresql/13.2_1/bin:$PATH
gem install pg
# and finally
=> Building native extensions. This could take a while...
=> Successfully installed pg-1.2.3
=> Parsing documentation for pg-1.2.3
=> Installing ri documentation for pg-1.2.3
=> Done installing documentation for pg after 1 seconds
=> 1 gem installed
Run Code Online (Sandbox Code Playgroud)
gem通过为适当的环境变量添加前缀来伪造.如果您是从MacPorts安装的,那么您应该能够完成以下过程:
% /opt/local/lib/postgresql91/bin/pg_config
BINDIR = /opt/local/lib/postgresql91/bin
DOCDIR = /opt/local/share/doc/postgresql
HTMLDIR = /opt/local/share/doc/postgresql
INCLUDEDIR = /opt/local/include/postgresql91
PKGINCLUDEDIR = /opt/local/include/postgresql91
INCLUDEDIR-SERVER = /opt/local/include/postgresql91/server
LIBDIR = /opt/local/lib/postgresql91
PKGLIBDIR = /opt/local/lib/postgresql91
LOCALEDIR = /opt/local/share/locale
MANDIR = /opt/local/share/man
SHAREDIR = /opt/local/share/postgresql91
SYSCONFDIR = /opt/local/etc/postgresql91
PGXS = /opt/local/lib/postgresql91/pgxs/src/makefiles/pgxs.mk
CONFIGURE = '--prefix=/opt/local' '--sysconfdir=/opt/local/etc/postgresql91' '--bindir=/opt/local/lib/postgresql91/bin' '--libdir=/opt/local/lib/postgresql91' '--includedir=/opt/local/include/postgresql91' '--datadir=/opt/local/share/postgresql91' '--mandir=/opt/local/share/man' '--with-includes=/opt/local/include' '--with-libraries=/opt/local/lib' '--with-openssl' '--with-bonjour' '--with-readline' '--with-zlib' '--with-libxml' '--with-libxslt' '--enable-thread-safety' '--enable-integer-datetimes' '--with-ossp-uuid' 'CC=/usr/bin/gcc-4.2' 'CFLAGS=-pipe -O2 -arch x86_64' 'LDFLAGS=-L/opt/local/lib -arch x86_64' 'CPPFLAGS=-I/opt/local/include -I/opt/local/include/ossp'
CC = /usr/bin/gcc-4.2
CPPFLAGS = -I/opt/local/include -I/opt/local/include/ossp -I/opt/local/include/libxml2 -I/opt/local/include
CFLAGS = -pipe -O2 -arch x86_64 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wformat-security -fno-strict-aliasing -fwrapv
CFLAGS_SL =
LDFLAGS = -L/opt/local/lib -arch x86_64 -L/opt/local/lib -L/opt/local/lib -Wl,-dead_strip_dylibs
LDFLAGS_EX =
LDFLAGS_SL =
LIBS = -lpgport -lxslt -lxml2 -lssl -lcrypto -lz -lreadline -lm
VERSION = PostgreSQL 9.1beta1
Run Code Online (Sandbox Code Playgroud)
从那里,拔出LIBDIR,INCLUDEDIR,CPPFLAGS,LIBS和LDFLAGS(我认为将让你在运行一个是LIBDIR但是,).那你就跑了:
setenv PATH /opt/local/lib/postgresql91/bin:${PATH}
sudo env LDFLAGS=-L`pg_config --libdir` CPPFLAGS=`pg_config --cppflags` gem install pg
Run Code Online (Sandbox Code Playgroud)
那应该为你做.如果没有,请告诉我.
我们遇到的问题非常奇怪.
ruby -v # was ok (rbenv)
gem -v # was ok (rbenv)
Run Code Online (Sandbox Code Playgroud)
但是当我们实际进行捆绑安装时,没有为rbenv安装的ruby版本安装bundler,因此,当我们键入bundle install时,它使用了系统的bundler.
因此,在运行bundle install之前,请确保已通过运行安装了bundler
gem install bundler
Run Code Online (Sandbox Code Playgroud)
Postgres.app 中的 libpq 无法在基于 ARM 的 Mac 上运行,因为 Postgres.app 没有针对 ARM 发布(仅发布通用 Intel/ARM 包,这只是 ARM64 上的 x86_64 模拟):
~ > file /Applications/Postgres.app/Contents/Versions/13/lib/libpq.dylib
/Applications/Postgres.app/Contents/Versions/13/lib/libpq.dylib: Mach-O 64-bit dynamically linked shared library x86_64
Run Code Online (Sandbox Code Playgroud)
因此,我决定将 libpq 与 Homebrew 分开安装:
~ > file /Applications/Postgres.app/Contents/Versions/13/lib/libpq.dylib
/Applications/Postgres.app/Contents/Versions/13/lib/libpq.dylib: Mach-O 64-bit dynamically linked shared library x86_64
Run Code Online (Sandbox Code Playgroud)
然后安装 pg 就可以了:
brew install libpq
Run Code Online (Sandbox Code Playgroud)
(配备 Apple M1 CPU 的 MacBook Pro 13" 2020 上的 MacOS 11.6 Big Sur)
| 归档时间: |
|
| 查看次数: |
65569 次 |
| 最近记录: |