bundle installでpgのインストールエラーが出た時の対処法
タイトルにもあるようにbundle install
でエラーが起きました。
途中部分を端折ってますが以下のようなコンソール画面が出ているはずです。
$ bandle install Fetching gem metadata from https://rubygems.org/...... Fetching https://github.com/rails/webpacker.git Fetching rake 12.1.0 Installing rake 12.1.0 ..... ..... ..... Fetching pg 0.21.0 Installing pg 0.21.0 with native extensions Gem::Ext::BuildError: ERROR: Failed to build gem native extension. ..... ..... extconf failed, exit code 1 ..... ..... An error occurred while installing pg (0.21.0), and Bundler cannot continue. Make sure that `gem install pg -v '0.21.0'` succeeds before bundling. In Gemfile: pg
原因
pgをインストールするための関連ファイルが足りないことが原因です
環境
解決方法
$ brew install postgresql
上のコマンドで不足しているファイルをインストールしましょう。
これで$ bundle install
を実行してもpg
のエラーを吐かなくなると思います。
注意
extconf failed, exit code 1
がエラーに含まれていなければ直らないかもしれません。その時はMake sure that `gem install pg -v '0.21.0'` succeeds before bundling.
の指示に従ってみてください。