Just do IT

思うは招く

An error occurred while installing pg (1.2.3), and Bundler cannot continue エラーの対処

問題

rails new sample -d postgresql

したときに出たエラー。

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
An error occurred while installing pg (1.2.3), and Bundler cannot continue.
Make sure that `gem install pg -v '1.2.3' --source 'https://rubygems.org/'` succeeds before bundling.
Could not find gem 'pg (>= 0.18, < 2.0)' in any of the gem sources listed in your Gemfile.
Could not find gem 'pg (>= 0.18, < 2.0)' in any of the gem sources listed in your Gemfile.

解決

Railspostgresql を使うためのプラグインをインストールする。

sudo apt install libpq-dev