21

重複の可能性:
Postgres - 「pg」gem の最後のバージョン 0.14.0 でエラーが発生する

私はレールが初めてです。Herokuも使っているのでPostgreSQLを使いたいのですが、pggemのインストールに苦労しています。どうやらいくつかのファイルが不足していて、Makefile を作成できませんか?

私の宝石ファイルは次のようになります。

source 'https://rubygems.org'

gem 'rails', '3.2.6'
gem 'faker', '1.0.1'
gem 'pg', '0.12.2'
gem 'json'

group :development, :test do
  gem 'rspec-rails', '2.10.0'
end

group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails', '2.0.0'

group :test do
  gem 'capybara', '1.1.2'
  gem 'factory_girl_rails', '1.4.0'
end

実行bundle installすると、pg gem のインストール時に次のエラーが表示されます。

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

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb 
checking for pg_config... yes
Using config values from /usr/local/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** 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=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/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
    --with-pqlib
    --without-pqlib
    --with-libpqlib
    --without-libpqlib
    --with-ms/libpqlib
    --without-ms/libpqlib


Gem files will remain installed in /Users/KennyGWang/.bundler/tmp/18833/gems/pg-0.14.0 for inspection.
Results logged to /Users/KennyGWang/.bundler/tmp/18833/gems/pg-0.14.0/ext/gem_make.out
An error occured while installing pg (0.14.0), and Bundler cannot continue.
Make sure that `gem install pg -v '0.14.0'` succeeds before bundling.

homebrew を使用して postgresql をインストールしたbrew install postgresqlので、which psql/usr/local/bin/psql

どんな助けでも大歓迎です!

4

4 に答える 4

80

あなたはMacを使っていますか?もしそうなら - これを行う最も簡単な方法は

  1. Xcode がインストールされていることを確認します (アプリ ストアから入手できます)。
  2. 自作を使う
  3. brew install postgresql
  4. gem uninstall pg
  5. bundle installアプリケーションのルートまたはgem install pg
于 2012-07-11T19:32:21.240 に答える
10

postgresql のインストール手順

  1. PostgreSQL とそのライブラリをインストールする

    sudo apt-get install postgresql postgresql-contrib libpq-dev
    
  2. インストール後、postgresql のユーザーを作成します。

    sudo -u postgres createuser --superuser $USER
    

    また

    sudo -u postgres createuser pgs_root
    
  3. postgresql ユーザーのユーザー パスワードを設定します。

    sudo -u postgres psql postgres --set "user=$USER"
    postgres=# \passsword :user
    

    また

    sudo -u postgres psql postgres
    postgres=# \passsword pgs_root
    
  4. postgresql.conf ファイルを構成して、PostgreSQL が localhost をリッスンするか、外部 IP などでリッスンするようにします。この行を IP または 'localhost' に変更します。

    gedit /etc/postgresql/8.4/main/postgresql.conf listen_addresses = 'localhost'
    

mysql クエリ ブラウザと同様に、pgadmin と呼ばれる postgresql 用の GUI があります。インストールするには、このコマンドを実行します

sudo apt-get install pgadmin3
于 2012-07-11T19:42:15.340 に答える
4

pg の代わりにこれを含めるようにしてください

gem install postgres-pr

また

gem install ruby-pg

編集

これはもうしましたか?

$ sudo apt-get install postgresql

$ rails new pg -d postgres

http://www.funonrails.com/2011/03/getting-started-with-rails-3-postgres.html

于 2012-07-11T18:44:13.750 に答える
0

含めたエラーで推奨されたログmkmf.logを確認しましたか?

何らかの理由でMakefileを作成できませんでした。おそらく、必要なライブラリやヘッダーが不足しています。詳細については、mkmf.logファイルを確認してください。構成オプションが必要になる場合があります。

于 2012-07-11T19:10:08.860 に答える