Ruby on rails 为PostgreSQL、openssl库安装gem pg

Ruby on rails 为PostgreSQL、openssl库安装gem pg,ruby-on-rails,ruby,gem,openssl,pg,Ruby On Rails,Ruby,Gem,Openssl,Pg,我将RVM与ruby 2.0.0一起使用。当我尝试为PostgreSQL安装pggem时,我得到以下响应 gem安装页面 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 extco

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

gem安装页面

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
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
试图用谷歌搜索,显然问题出在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
还是同样的问题

尝试使用--使用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安装页面

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
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文件。但事实是,我已经用重新编译了它——用openssldir标志


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

为什么它总是发生?一旦你把你的问题贴在这里,你就可以自己解决了

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

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

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

尝试安装opensslNick,这不是验证,而是Ruby和Postgre使用不同的OpenSSL库。感谢您的帮助,我找到了一个解决方案。rvm pkg安装openssl rvm重新安装2.0.0 gem安装pg应该可以工作,依靠rvm帮助您管理openssl/依赖项。它被用作最标准的公认方式,表示“我们停止向rvm传递选项”,然后将这些选项传递给rvm将启动的命令