简体   繁体   English

rails - postgres错误:原因:不兼容的库版本:libpq.5.dylib需要1.0.0或更高版本,

[英]rails - postgres error: Reason: Incompatible library version: libpq.5.dylib requires version 1.0.0 or later,

I am stuck with the setup of Ruby (1.9.3), Rails and Postgres (9.0.8) on my Mac (10.6.8). 我在Mac(10.6.8)上遇到了Ruby(1.9.3),Rails和Postgres(9.0.8)的设置问题。 Everytime when I run rails console I get the following error: 每当我运行rails console我都会收到以下错误:

/Users/dc/.rvm/gems/ruby-1.9.3-head@global/gems/pg-0.13.2/lib/pg.rb:4:in `require': dlopen(/Users/dc/.rvm/gems/ruby-1.9.3-head@global/gems/pg-0.13.2/lib/pg_ext.bundle, 9): Library not loaded: @loader_path/../lib/libssl.dylib (LoadError)
  Referenced from: /usr/lib/libpq.5.dylib
  Reason: Incompatible library version: libpq.5.dylib requires version 1.0.0 or later, but libssl.0.9.8.dylib provides version 0.9.8 - /Users/dc/.rvm/gems/ruby-1.9.3-head@global/gems/pg-0.13.2/lib/pg_ext.bundle  
    from /Users/dc/.rvm/gems/ruby-1.9.3-head@global/gems/pg-0.13.2/lib/pg.rb:4:in `<top (required)>'
    from /Users/dc/.rvm/gems/ruby-1.9.3-head@global/gems/bundler-1.1.4/lib/bundler/runtime.rb:68:in `require'
    from /Users/dc/.rvm/gems/ruby-1.9.3-head@global/gems/bundler-1.1.4/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
    from /Users/dc/.rvm/gems/ruby-1.9.3-head@global/gems/bundler-1.1.4/lib/bundler/runtime.rb:66:in `each'
    from /Users/dc/.rvm/gems/ruby-1.9.3-head@global/gems/bundler-1.1.4/lib/bundler/runtime.rb:66:in `block in require'
    from /Users/dc/.rvm/gems/ruby-1.9.3-head@global/gems/bundler-1.1.4/lib/bundler/runtime.rb:55:in `each'
    from /Users/dc/.rvm/gems/ruby-1.9.3-head@global/gems/bundler-1.1.4/lib/bundler/runtime.rb:55:in `require'
    from /Users/dc/.rvm/gems/ruby-1.9.3-head@global/gems/bundler-1.1.4/lib/bundler.rb:119:in `require'
    from /Users/dc/Documents/Aptana Studio 3 Workspace/http/config/application.rb:7:in `<top (required)>'
    from /Users/dc/.rvm/gems/ruby-1.9.3-head@global/gems/railties-3.2.6/lib/rails/commands.rb:39:in `require'
    from /Users/dc/.rvm/gems/ruby-1.9.3-head@global/gems/railties-3.2.6/lib/rails/commands.rb:39:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

I really don't know how to fix this. 我真的不知道如何解决这个问题。 I already tried installing a different Postgres version and I still get the same error. 我已经尝试安装不同的Postgres版本,但仍然会出现同样的错误。

I ran into this also, but was able to fix it following the instructions on python pip install psycopg2 install error . 我也碰到了这个,但能够按照python pip install psycopg2安装错误的说明修复它。

First, make sure you have the most recent version of OpenSSL installed: 首先,确保安装了最新版本的OpenSSL

MacBook Pro:~> openssl version -a
OpenSSL 1.0.0c 2 Dec 2010
built on: Mon Jan  3 17:26:21 PST 2011
platform: darwin64-x86_64-cc
options:  bn(64,64) rc4(ptr,char) des(idx,cisc,16,int) idea(int) blowfish(idx) 
compiler: /usr/bin/gcc-4.2 -fPIC -fno-common -DOPENSSL_PIC -DZLIB -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -arch x86_64 -O3 -DL_ENDIAN -DMD32_REG_T=int -Wall
OPENSSLDIR: "/opt/local/etc/openssl"

...and note the OPENSSLDIR. ......并注意OPENSSLDIR。 On my system, it's in /opt/local/, because I installed it via MacPorts. 在我的系统上,它位于/ opt / local /,因为我是通过MacPorts安装的。 I just needed to update the symlinks in /usr/lib/ for libssl.dylib and libcrypto.dylib so that they pointed to the correct versions in /opt/local/lib instead of the old version in usr/lib: 我只需更新/ usr / lib /中的符号链接libssl.dylib和libcrypto.dylib,以便它们指向/ opt / local / lib中的正确版本而不是usr / lib中的旧版本:

MacBook Pro:~> ls -la /usr/lib/libssl.dylib 
lrwxr-xr-x  1 root  wheel  33 Aug 17 12:25 /usr/lib/libssl.dylib -> /opt/local/lib/libssl.1.0.0.dylib
MacBook Pro:~> ls -la /usr/lib/libcrypto.dylib 
lrwxr-xr-x  1 root  wheel  36 Aug 17 12:28 /usr/lib/libcrypto.dylib -> /opt/local/lib/libcrypto.1.0.0.dylib

You can create the links by using the ln command: 您可以使用ln命令创建链接:

sudo ln -s /path/to/postgres/install/lib/libcrypto.dylib /usr/lib/libcrypto.dylib
sudo ln -s /path/to/postgres/install/lib/libssl.dylib /usr/lib/libssl.dylib

Symlinking the files as above didn't work for me. 如上所述拼凑文件对我来说不起作用。 pg would always look at libssl-0.9.8.dylib. pg总是会看libssl-0.9.8.dylib。

This question contains the right answer it seems: gem install pg --with-pg-config works, bundle fails 这个问题似乎包含正确答案: gem install pg --with-pg-config工作,bundle失败

It boils down to 归结为

bundle config build.pg --with-pg-config=/Library/PostgreSQL/9.1/bin/pg_config

(or whichever pg you are targeting) (或者你所针对的那个)

followed by gem uninstall pg and then bundle install 然后是gem uninstall pg ,然后是bundle install

In one project this solution ("gem install & uninstall pg") was fine. 在一个项目中,这个解决方案(“gem install&uninstall pg”)很好。

But in another project, that uses the same rails and Postgres version, I had to be explicit with version in gemfile to make it work: 但是在另一个使用相同rails和Postgres版本的项目中,我必须明确使用gemfile中的版本才能使它工作:

  gem 'pg', '0.14.1'

Install new PostgreSQL version (i've used homebrew) 安装新的PostgreSQL版本(我用过自制软件)

brew install postgres

Then reinstall the gem pg: 然后重新安装gem pg:

gem uninstall pg
gem install pg

Hope it helps. 希望能帮助到你。

找到了一个适合我的解决方案: https//github.com/PostgresApp/PostgresApp/issues/109

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM