ruby-on-rails - 为 PostgreSQL、openssl 库安装 gem pg

标签 ruby-on-rails ruby gem openssl pg

我将 RVM 与 ruby​​ 2.0.0 一起使用。当我尝试为 PostgreSQL 安装 pg gem 时,我得到以下响应。

gem 安装 pg

Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

    /usr/local/rvm/rubies/ruby-2.0.0-p0/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/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
    --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=/usr/local/rvm/rubies/ruby-2.0.0-p0/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}/
    --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 /usr/local/rvm/gems/ruby-2.0.0-p0/gems/pg-0.14.1 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.0.0-p0/gems/pg-0.14.1/ext/gem_make.out

尝试用谷歌搜索,显然问题出在 OpenSSL 库上,因为在 mkmf.log 中输出是

have_library: checking for PQconnectdb() in -lpq... -----------------$

"gcc -o conftest -I/usr/local/rvm/rubies/ruby-2.0.0-p0/include/ruby-2$
conftest.c: In function 't':
conftest.c:8:32: warning: variable 'p' set but not used [-Wunused-but$
/usr/lib/libpq.so: undefined reference to `SSL_get_error@OPENSSL_1.0.$
/usr/lib/libpq.so: undefined reference to `SSL_get_peer_certificate@O$
/usr/lib/libpq.so: undefined reference to `SSL_CTX_load_verify_locati$
/usr/lib/libpq.so: undefined reference to `SSL_set_ex_data@OPENSSL_1.$
/usr/lib/libpq.so: undefined reference to `SSL_use_certificate_file@O$
/usr/lib/libpq.so: undefined reference to `ENGINE_free@OPENSSL_1.0.0'
/usr/lib/libpq.so: undefined reference to `SSL_write@OPENSSL_1.0.0'
/usr/lib/libpq.so: undefined reference to `ERR_get_error@OPENSSL_1.0.$
/usr/lib/libpq.so: undefined reference to `ENGINE_by_id@OPENSSL_1.0.0'
/usr/lib/libpq.so: undefined reference to `SSL_use_PrivateKey@OPENSSL$
/usr/lib/libpq.so: undefined reference to `X509_get_subject_name@OPEN$
/usr/lib/libpq.so: undefined reference to `ENGINE_init@OPENSSL_1.0.0'
/usr/lib/libpq.so: undefined reference to `SSL_load_error_strings@OPE$
/usr/lib/libpq.so: undefined reference to `X509_STORE_set_flags@OPENS$
/usr/lib/libpq.so: undefined reference to `SSL_new@OPENSSL_1.0.0'

然后我使用中指定的 OpenSSL 目录重新安装了 ruby​​

openssl version -d
OPENSSLDIR: "/usr/lib/ssl"
rvm reinstall 2.0.0 --with-openssl-dir=/usr/lib/ssl

还是一样的问题。

尝试使用 --with-pg-config 标志安装 gem。同样的问题。

尝试过在许多网站上找到的常见解决方法

mv $rvm_path/usr/lib $rvm_path/usr/rvm_lib
gem install pg
mv $rvm_path/usr/rvm_lib $rvm_path/usr/lib

这次的错误有所不同。

gem 安装 pg

Error loading RubyGems plugin "/usr/local/rvm/gems/ruby-2.0.0-p0@global/gems/rubygems-bundler-1.1.1/lib/rubygems_plugin.rb": /usr/local/rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/openssl.so: undefined symbol: SSLv2_method - /usr/local/rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/openssl.so (LoadError)
ERROR:  Loading command: install (LoadError)
    /usr/local/rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/openssl.so: undefined symbol: SSLv2_method - /usr/local/rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/x86_64-linux/openssl.so
ERROR:  While executing gem ... (NoMethodError)
    undefined method `invoke_with_build_args' for nil:NilClass

假设它仍然尝试从 Ruby 目录中获取 openssl.so - 问题是 Ruby 使用了错误的 openssl.so 文件。但事实是,我已经用 --with-openssl-dir 标志重新编译了它。

有什么建议吗?在过去的 10 个小时里,我一直在尝试我能找到的所有解决方法。

最佳答案

为什么总是这样?一旦您在此处发布您的问题,您就可以自行解决。

解决方案很简单 - 我在重新安装 ruby​​ 时错过了“--”。

openssl version -d
OPENSSLDIR: "/usr/lib/ssl"
rvm reinstall 2.0.0 -- --with-openssl-dir=/usr/lib/ssl

这解决了问题。希望它能帮助其他人。

关于ruby-on-rails - 为 PostgreSQL、openssl 库安装 gem pg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15186924/

相关文章:

ruby-on-rails - Rails 3. 无法在任何来源中找到 libv8-3.3.10.4

ruby-on-rails - Rails 对 nil 值的唯一性验证

mysql - 查找一对多连接表满足一个条件但不满足另一个条件的所有记录

ruby-on-rails - ActiveRecord 搜索分面计数

ruby-on-rails - Rails Minitest 没有运行测试类

ruby-on-rails - rails : optimizing a controller action (security checking)

Ruby: block 和产量

ruby-on-rails - 使用 rolify 查找具有特定角色的所有用户

ruby-on-rails - 如何将多个模式加载到 Rails 引擎或应用程序中?

ruby - 安装 gems : cannot load such file -- zlib 时出错