gem install pg在进行bundle install / RoR时无法正常工作

时间:2014-07-07 16:31:48

标签: ruby-on-rails ruby postgresql

修改

对我有用的是:

brew doctor

然后我不得不输入几个文件并删除它要求我的一些内容。

然后我跑了

sudo gem install pg

它有效。不知道为什么它只适用于'sudo',但是当我尝试之前没有它失败

我使用了捆绑器来安装一堆宝石(大多数都失败了,我花了几个小时查看有关如何安装特定宝石的互联网帖子。

目前正在运行

bundle install

抱怨以下

jacks-MacBook-Pro:techendo jsw$ bundle install
Fetching source index from https://rubygems.org/
Using rake 10.3.2
Using i18n 0.6.9
Using minitest 4.7.5
Using multi_json 1.10.1
Using thread_safe 0.3.4
Using tzinfo 0.3.39
Using activesupport 4.0.3
Using builder 3.1.4
Using erubis 2.7.0
Using rack 1.5.2
Using rack-test 0.6.2
Using actionpack 4.0.3
Using mime-types 1.25.1
Using polyglot 0.3.5
Using treetop 1.4.15
Using mail 2.5.4
Using actionmailer 4.0.3
Using active_utils 2.2.1
Using json 1.8.1
Using active_shipping 0.12.2
Using activemodel 4.0.3
Using activerecord-deprecated_finders 1.0.3
Using arel 4.0.2
Using activerecord 4.0.3
Using addressable 2.3.6
Using mini_portile 0.6.0
Using nokogiri 1.6.2.1
Using ruby-hmac 0.4.0
Using amazon-ecs 2.2.5
Using aws-sdk 1.42.0
Using bcrypt 3.1.7
Using multi_xml 0.5.5
Using httparty 0.13.1
Using multipart-post 2.0.0
Using faraday 0.9.0
Using jwt 1.0.0
Using oauth2 0.9.4
Using bitly 0.10.1
Using sass 3.2.19
Using bootstrap-sass 3.1.1.1
Using buftok 0.2.0
Using cinch 2.1.0
Using climate_control 0.0.3
Using cocaine 0.5.4
Using daemons 1.1.9
Using dalli 2.7.2
Using delayed_job 4.0.1
Using delayed_job_active_record 4.0.1

Using orm_adapter 0.5.0
Using thor 0.19.1
Using railties 4.0.3
Using warden 1.2.3
Using devise 3.2.4
Using diff-lcs 1.2.5
Using equalizer 0.0.9
Using exception_notification 4.0.1
Using excon 0.34.0
Using execjs 2.1.0
Using friendly_id 5.0.4
Using geocoder 1.2.1
Using gibbon 1.1.3
Using google_custom_search 0.3.1
Using heroku-api 0.3.18
Using heroku-deflater 0.5.3
Using hike 1.2.3
Using htmlentities 4.3.2
Using http_parser.rb 0.6.0
Using http 0.6.1
Using imgkit 1.4.1
Using jquery-rails 3.1.0
Using jquery-ui-rails 4.2.1
Using kgio 2.9.2
Using libv8 3.16.14.3
Using tilt 1.4.1
Using mail_view 2.0.4
Using mandrill-api 1.0.51
Using memcachier 0.0.2
Using memoizable 0.4.2
Using meta-tags 2.0.0
Using mixpanel-ruby 1.4.0
Using naught 1.0.0
Using nested_form 0.3.2
Using newrelic_rpm 3.8.1.221
Using paperclip 4.1.1

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /Users/jsw/.rvm/rubies/ruby-2.1.1/bin/ruby extconf.rb --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
Using config values from /Applications/Postgres.app/Contents/MacOS/bin/pg_config
sh: /Applications/Postgres.app/Contents/MacOS/bin/pg_config: No such file or directory
sh: /Applications/Postgres.app/Contents/MacOS/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.

Provided configuration options:
    --with-opt-dir
    --without-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=/Users/jsw/.rvm/rubies/ruby-2.1.1/bin/ruby
    --with-pg
    --without-pg
    --with-pg-config
    --with-pg-dir
    --without-pg-dir
    --with-pg-include
    --without-pg-include=${pg-dir}/include
    --with-pg-lib
    --without-pg-lib=${pg-dir}/lib

extconf failed, exit code 1

Gem files will remain installed in /Users/jsw/.rvm/gems/ruby-2.1.1/gems/pg-0.17.1 for inspection.
Results logged to /Users/jsw/.rvm/gems/ruby-2.1.1/extensions/x86_64-darwin-12/2.1.0-static/pg-0.17.1/gem_make.out
An error occurred while installing pg (0.17.1), and
Bundler cannot continue.
Make sure that `gem install pg -v '0.17.1'` succeeds
before bundling.

在另一个堆栈溢出帖子上建议以下内容     以下是我修复它的方法(使用自制程序):

Install another build of Xcode Tools (typing 'brew update' in the terminal will prompt     you to update the Xcode build tools)
brew update
brew install postgresql

但是当我做的时候

brew install postgresql

我得到以下内容:

Warning: postgresql-9.3.4 already installed, it's just not linked

我找不到涵盖如何执行此操作的帖子。有人可以解释我想如何链接这个吗?或者如何

libpq-fe.h header

我试过

brew uninstall postgresql
brew install postgresql

给了我

brew uninstall postgresql
Uninstalling /usr/local/Cellar/postgresql/9.3.4...


jacks-MacBook-Pro:techendo jsw$ brew install postgresql
==> Downloading https://downloads.sf.net/project/mach
Already downloaded: /Library/Caches/Homebrew/postgresql-9.3.4.mavericks.bottle.2.tar.gz
==> Pouring postgresql-9.3.4.mavericks.bottle.2.tar.g
==> Caveats
If builds of PostgreSQL 9 are failing and you have version 8.x installed,
you may need to remove the previous version first. See:
  https://github.com/Homebrew/homebrew/issues/issue/2510

To migrate existing data from a previous major version (pre-9.3) of PostgreSQL, see:
  http://www.postgresql.org/docs/9.3/static/upgrading.html

When installing the postgres gem, including ARCHFLAGS is recommended:
  ARCHFLAGS="-arch x86_64" gem install pg

To install gems without sudo, see the Homebrew wiki.

To have launchd start postgresql at login:
    ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
Then to load postgresql now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Or, if you don't want/need launchctl, you can just run:
    postgres -D /usr/local/var/postgres
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink share/man/man3/SPI_connect.3
/usr/local/share/man/man3 is not writable.

You can try again using:
  brew link postgresql
==> Summary
  /usr/local/Cellar/postgresql/9.3.4: 2921 files, 38M

它仍然表示它已安装但没有链接,所以我跑了

brew link postgresql

我得到以下

jacks-MacBook-Pro:techendo jsw$ brew link postgresql
Linking /usr/local/Cellar/postgresql/9.3.4... 
Error: Could not symlink share/man/man3/SPI_connect.3
/usr/local/share/man/man3 is not writable.

有人建议我做

ARCHFLAGS="-arch x86_64" gem install pg

我做了什么

jacks-MacBook-Pro:techendo jsw$ ARCHFLAGS="-arch x86_64" gem install pg
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

    /Users/jsw/.rvm/rubies/ruby-2.1.1/bin/ruby extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
 --with-pg-config=/path/to/pg_config
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.

Provided configuration options:
    --with-opt-dir
    --without-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=/Users/jsw/.rvm/rubies/ruby-2.1.1/bin/ruby
    --with-pg
    --without-pg
    --with-pg-config
    --without-pg-config
    --with-pg_config
    --without-pg_config
    --with-pg-dir
    --without-pg-dir
    --with-pg-include
    --without-pg-include=${pg-dir}/include
    --with-pg-lib
    --without-pg-lib=${pg-dir}/lib

extconf failed, exit code 1

Gem files will remain installed in /Users/jsw/.rvm/gems/ruby-2.1.1/gems/pg-0.17.1 for inspection.
Results logged to /Users/jsw/.rvm/gems/ruby-2.1.1/extensions/x86_64-darwin-12/2.1.0-static/pg-0.17.1/gem_make.out

2 个答案:

答案 0 :(得分:4)

对我有用的是:

brew doctor

然后我不得不打开几个文件并删除它要求我做的一些事情。

然后我跑了

sudo gem install pg

它有效。不知道为什么它只适用于'sudo',但是当我尝试之前没有它失败

答案 1 :(得分:1)

问题与这个问题相同:

Can't find the 'libpq-fe.h header when trying to install pg gem

brew install postgresql