[英]PostgreSQL ruby gem installation issue
我在安裝 Postgres gem 時遇到了一些麻煩。 當我運行時:
gem install pg -v '0.19.0'
它打印:
Successfully installed pg-0.19.0
Parsing documentation for pg-0.19.0
Done installing documentation for pg after 2 seconds
1 gem installed
但是當我運行時:
bundle install
它停在 pg gem 上並打印:
An error occurred while installing pg (0.19.0), and Bundler cannot continue.
Make sure that `gem install pg -v '0.19.0'` succeeds before bundling.
整個日志是:
sh: /usr/pgsql-9.1/bin/pg_config: No such file or directory
sh: /usr/pgsql-9.1/bin/pg_config: No such file or directory
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** 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.
gem env
輸出:
/ruby/2.3.0/rubygems/commands/environment_command.rb:154: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777
RubyGems Environment:
- RUBYGEMS VERSION: 2.5.1
- RUBY VERSION: 2.3.0 (2015-12-25 patchlevel 0) [x86_64-darwin16]
- INSTALLATION DIRECTORY: /.rvm/gems/ruby-2.3.0
- USER INSTALLATION DIRECTORY: /.gem/ruby/2.3.0
- RUBY EXECUTABLE: /.rvm/rubies/ruby-2.3.0/bin/ruby
- EXECUTABLE DIRECTORY: /.rvm/gems/ruby-2.3.0/bin
- SPEC CACHE DIRECTORY: /.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /.rvm/rubies/ruby-2.3.0/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-16
- GEM PATHS:
- /.rvm/gems/ruby-2.3.0
- /.rvm/gems/ruby-2.3.0@global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /.rvm/gems/ruby-2.3.0/bin
- /.rvm/gems/ruby-2.3.0@global/bin
- /.rvm/rubies/ruby-2.3.0/bin
- /.rvm/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
我很驚訝 gem 在不知道 PostgreSQL 安裝位置的情況下安裝了 pg。
錯誤信息
sh: /usr/pgsql-9.1/bin/pg_config: No such file or directory
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
是代碼無法定位標題的結果,這是未找到pg_config
的結果。
簡單的解決方法是使用包含pg_config
的目錄臨時更新您的 PATH。 您可以使用locate
輕松做到這一點:
locate pg_config
在我的系統上返回:
/Applications/Postgres.app/Contents/Versions/9.5/bin/pg_config
除其他事項外。 您想要的pg_config
將位於您想要與 Ruby 一起使用的任何 PostgreSQL 的bin
目錄中。
如果您沒有locate
運行,您還可以執行以下操作:
find / -name pg_config -type f 2>/dev/null
並等待find
搜索您的驅動器。 (為您提供locate
非常有幫助,因此如果它沒有運行,我建議您啟動它。)
使用pg_config
的路徑修改您的 PATH,然后運行您的命令:
PATH=/Applications/Postgres.app/Contents/Versions/9.5/bin:$PATH gem install pg && bundle install
當然,修改系統的 pg_config 路徑。
刪除gem install pg &&
並簡單地運行bundle install
也可能起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.