PostgreSQL ruby​​ gem安装问题

时间:2016-10-16 16:38:59

标签: ruby-on-rails ruby postgresql

我在安装Postgres宝石时遇到了一些麻烦。我跑的时候:

 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

1 个答案:

答案 0 :(得分:0)

我很惊讶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

等等。对于要与Ruby一起使用的PostgreSQL,您想要的pg_config将位于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