99

バンドル(バンドルインストール)を実行しようとすると、常に

Installing pg (0.13.2) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /Users/ryan/.rvm/rubies/ruby-1.9.2-p290/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/ryan/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
    --with-pg
    --without-pg
    --with-pg-dir
    --without-pg-dir
    --with-pg-include
    --without-pg-include=${pg-dir}/include
    --with-pg-lib
    --without-pg-lib=${pg-dir}/lib
    --with-pg-config
    --without-pg-config
    --with-pg_config
    --without-pg_config


Gem files will remain installed in /Users/ryan/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.13.2 for inspection.
Results logged to /Users/ryan/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.13.2/ext/gem_make.out
An error occured while installing pg (0.13.2), and Bundler cannot continue.
Make sure that `gem install pg -v '0.13.2'` succeeds before bundling.

私はMacOSX 10.6を使用していますが、インストールされているPostgreSQLのバージョンは9.1です。問題がlibpq-devにあることがわかりましたが、どうすればそれをインストール/修正できますか?

4

16 に答える 16

78

エラー ログに記載されているように、pg_config へのパスを渡す必要があります。以下を使用して gem をインストールしてみてください。

gem install pg -- --with-pg-config= 'PATH_TO_YOUR_PG_CONFIG'

pg_config の場所がわからない場合、Linux または Mac を使用していると仮定すると、次のコマンドを実行できます。

which pg_config

postgres のインストール方法に応じて、pg-config の場所が異なる場合があります。

于 2012-03-12T15:03:05.263 に答える
22

自作の場合は、次のように入力します。

$ brew install postgresql

持っていない場合は、端末に次のように入力してダウンロードします。

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install )"

于 2014-02-11T13:33:19.097 に答える
8

インストールする必要があるのは次のlibpq-devとおりです。

sudo apt-get install libpq-dev

その後、gem は正常にインストールされます。

于 2012-07-23T17:43:46.670 に答える
7

インストール後の手順に従ってください: http://postgresapp.com/documentation/configuration-ruby.html

pg gem をインストールするには、( http://postgresapp.com/documentation/cli-tools.htmlで指定されているように) $PATH が正しく設定されていることを確認してから、次のコマンドを実行します。

sudo ARCHFLAGS="-arch x86_64" gem install pg

両方のページを読むことを強くお勧めします。それらをすくい取っただけで、私の人生の1時間を失いました。それらを読んで、問題を解決してください。

于 2014-10-01T01:19:36.277 に答える
3

私が抱えていた問題は、何らかの理由で /usr/bin/gcc-4.2 でコンパイルしようとしたことでした。mkmf.rb (スタック トレースで見た) の try_cpp を変更して、失敗したコンパイル行で例外を発生させることで、これを発見しました。

gcc を gcc-4.2 にソフトリンクしたところ、うまくいきました。

sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2

なぜ gcc-4.2 を使おうとしたのですか? わかりません。

実際のコンパイル行:

/usr/bin/gcc-4.2 -E -I/Users/dfrankow/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/x86_64-darwin11.4.0 -I/Users/dfrankow/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/ruby/backward -I/Users/dfrankow/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE   -I/usr/local/Cellar/postgresql/9.1.4/include  -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration  -fno-common -pipe  conftest.c -o conftest.i (RuntimeError)
于 2012-07-30T18:45:53.893 に答える
1

I had the same problem in my openSUSE13.1 KDE machine. Before that issue I encountered I had installed only the packages postgresql and postgresql-server using zypper command. Then installed again 2 more packages :

[arup@to_do_app]$ sudo zypper in postgresql-devel postgresql-contrib
root's password:
Loading repository data...
Reading installed packages...
Resolving package dependencies...
#....

Then, I ran again bundle install, and success!!!

于 2014-12-20T19:26:12.323 に答える
1

ビルド構成オプションbundle config build.pg --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_configを設定し、オプションなしで使用gem install pgできます (pg_config へのパスは異なる場合があります。これは Postgresapp 9.3.5.0 用です)。

于 2014-09-01T14:08:34.087 に答える
0

動作する OSX ソリューションについては、このガイドを参照してくださいhttp://krugerdavid.com/journal/how-to-install-xcode-homebrew-git-rvm-postgresql-ruby-1-9-3-on-snow-leopard/

homebrew を使用して PostgreSQL をインストールする方法について説明します。OSX 10.8.3、PostgreSQL 9.2.3、および Ruby 2.0.0-p0 でテスト済みで動作しています

于 2013-03-26T22:36:41.603 に答える
0

Fedora の場合:

dnf install postgresql-devel
于 2016-08-06T12:06:27.420 に答える
0

El Capitan でうまくいったのは、Ruby をシステムのデフォルトから 2.3.1 にアップグレードしたことで、pggem に必要な正しいライブラリが見つかったようです。

于 2016-08-15T02:14:42.947 に答える
0

まず、Homebrew のバージョンをアンインストールします。--force オプションを指定すると、すべてのバージョンがアンインストールされます。

brew rm postgresql --force

バージョンに応じてパスを変更します。

sudo /sbin/SystemStarter stop postgresql-8.4
sudo rm -rf /Applications/PostgreSQL\ 8.4
sudo rm -rf /etc/postgres-reg.ini
sudo rm -rf /Library/StartupItems/postgresql-8.4
sudo rm -rf /Library/PostgreSQL/8.4
sudo dscl . delete /users/postgres

/etc/profile を編集し、「postgres」を参照するすべての行を削除します。

nano /etc/profile

PostgreSQL をインストールする

brew update
brew install postgresql

PG GEM のインストール

gem install pg

それでおしまい。よろしく。

于 2013-12-02T20:43:13.753 に答える
0

まず、lib ファイルに移動して、端末に postrgresql ファイルがあるかどうかを確認できます。cd ~/opt/local/lib/ に移動し、ls と入力して Enter ボタンを押します。これにより、lib ディレクトリにあるすべてのファイルのリストが表示されます。

1.postreseql がない場合は、macports からダウンロードできます。sudo ポート インストール postgresql93 @9.3.2_1

インストールをバンドルしようとしているフォルダに cd で戻ります。

  1. 持っている、またはダウンロードしたばかりの postgesql ファイルで pg を動作させるには、gem install pg -- --with-pg-config=/opt/local/lib/postgresql93/bin/pg_config を使用します。

bundle install を実行します

于 2014-02-10T08:51:25.280 に答える