ste*_*coy 5 postgresql macos ruby-on-rails libpq pg
Heyo.如果在另一个帖子中回答了这个问题,我会提前道歉.我搜索了网站,但没有找到答案.但是,最接近的相关问题是启动server-libq.5.dylib时Ruby on Rails/PostgreSQL - Library not Loaded错误,但它从未得到解决,答案对我没有帮助.
我正在尝试在我的Mac OSX 10.6.8上运行PostgreSQL.我已经安装了Ruby 1.9.3p392和Rails 3.2.13.
由于我的10.6.8和PostGresApp需要10.7+,我尝试使用此处提供的手动安装程序(v9.2.3)安装PG:http://www.enterprisedb.com/products-services-training/pgdownload
我首先将它安装到默认路径:/Library/PostgreSQL/9.2/.然后我安装了pg gem(PATH=$PATH:/Library/PostgreSQL/9.2/bin sudo gem install pg).当我尝试rails s启动localhost时,我收到了以下错误.
经过一些阅读,我猜测它可能是一个路径错误,所以我删除了pg gem,然后使用了postgresql卸载程序.然后我重新安装了/users/stewartmccoy/Library/PostgreSQL/9.2/...中的pg,然后重新安装了pg gem.但我仍然得到同样的错误.
有关如何正确安装PostgreSQL并让我的rails服务器运行的任何想法?
stewart-mccoys-macbook:footy_subs stewartmccoy$ rails s
/Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.14.1/lib/pg.rb:4:in `require': dlopen(/Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.14.1/lib/pg_ext.bundle, 9): Library not loaded: libpq.5.dylib (LoadError)
Referenced from: /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.14.1/lib/pg_ext.bundle
Reason: image not found - /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.14.1/lib/pg_ext.bundle
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.14.1/lib/pg.rb:4:in `<top (required)>'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:72:in `require'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:70:in `each'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:70:in `block in require'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:59:in `each'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:59:in `require'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392@global/gems/bundler-1.3.4/lib/bundler.rb:132:in `require'
from /Users/stewartmccoy/Code/footy_subs/config/application.rb:13:in `<top (required)>'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/commands.rb:53:in `require'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/commands.rb:53:in `block in <top (required)>'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/commands.rb:50:in `tap'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
stewart-mccoys-macbook:footy_subs stewartmccoy$ gem uninstall pgSuccessfully uninstalled pg-0.14.1
stewart-mccoys-macbook:footy_subs stewartmccoy$ PATH=$PATH:/users/stewartmccoy/Library/PostgreSQL/9.2/bin sudo gem install pg
Password:
Fetching: pg-0.14.1.gem (100%)
Building native extensions. This could take a while...
Successfully installed pg-0.14.1
1 gem installed
Installing ri documentation for pg-0.14.1...
Installing RDoc documentation for pg-0.14.1...
stewart-mccoys-macbook:footy_subs stewartmccoy$ rails s
/Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.14.1/lib/pg.rb:4:in `require': dlopen(/Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.14.1/lib/pg_ext.bundle, 9): Library not loaded: libpq.5.dylib (LoadError)
Referenced from: /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.14.1/lib/pg_ext.bundle
Reason: image not found - /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.14.1/lib/pg_ext.bundle
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.14.1/lib/pg.rb:4:in `<top (required)>'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:72:in `require'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:70:in `each'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:70:in `block in require'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:59:in `each'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:59:in `require'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392@global/gems/bundler-1.3.4/lib/bundler.rb:132:in `require'
from /Users/stewartmccoy/Code/footy_subs/config/application.rb:13:in `<top (required)>'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/commands.rb:53:in `require'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/commands.rb:53:in `block in <top (required)>'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/commands.rb:50:in `tap'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Run Code Online (Sandbox Code Playgroud)
错误的关键部分是:
Library not loaded: libpq.5.dylib (LoadError)
Run Code Online (Sandbox Code Playgroud)
这表明ruby libpq在运行时找不到.为了解决这个问题,您应该将DYLD_LIBRARY_PATH环境变量设置为指向libPostgreSQL安装目录,无论是全局还是用于启动Rails的包装脚本.有关更多信息,请参阅此超级用户问题.
该Pg宝石可以编译和安装过程中找到库,因为pg_config可执行文件的PATH,它使用的是发现libpq.它似乎不存储在运行时使用的路径,因此您必须自己设置运行时动态链接器.
一个简单的包装脚本(如果你不想修改你的全局环境)是这样的:
#!/bin/bash
export DYLD_LIBRARY_PATH=/path/to/pg/lib
exec rails "$@"
Run Code Online (Sandbox Code Playgroud)
"$ @"基本上意味着"将所有参数传递给此脚本,就像它们直接传递到此处一样".它保留了正确的引用,实质上意味着rails命令无法告诉你没有直接运行它.
我想把我的两分钱放在上面的答案上。
有时只需重新安装pggem 就足够了。
gem uninstall pg && gem install pg
Run Code Online (Sandbox Code Playgroud)
就我而言,我将 postgresql 服务器从9.6up升级14.x到 dylib 路径已更改。
/opt/local/lib/postgresql96/libpq.5.dylib->/opt/local/lib/postgresql14/libpq.5.dylib
gem 使用pg_config来确定/opt/local/lib/postgresql[version]文件夹(名为PKGLIBDIR)的路径。要为 gem rake 构建本机库,请通过从pg_config编译中获取动态库来设置动态库的路径。一旦pggem 被编译,路径就永远链接在一起。因此,重新安装会重新编译并重新链接新库的路径。
| 归档时间: |
|
| 查看次数: |
2597 次 |
| 最近记录: |