2
2

More than 1 year has passed since last update.

エラー:An error occurred while installing pg (1.4.5), and Bundler cannot continue.

Posted at

はじめに

プログラミング初心者による備忘録です。

今回はrenderにデプロイされているアプリをAWSのEC2環境へ移す際にエラーが発生したので、その原因と解決方法です。

何をしている時にエラーが出たのか

以下のコマンドでEC2内にローカルと同じバージョンの bundlerをインストールしようとしました。

[ec2-user@ip-000-00-00-000 hoge]$ gem install bundler -v 2.1.4

[ec2-user@ip-000-00-00-000 hoge]$ bundle install

すると以下のエラーが発生。

[ec2-user@ip-000-00-00-000 hoge]$ bundle
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby, x86_64-linux but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching gem metadata from https://rubygems.org/.........

    中略

Fetching pg 1.4.5
Installing pg 1.4.5 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/pg-1.4.5/ext
/home/ec2-user/.rbenv/versions/2.6.5/bin/ruby -I /home/ec2-user/.rbenv/versions/2.6.5/lib/ruby/2.6.0 -r ./siteconf20230111-21011-1k4naz0.rb extconf.rb
Calling libpq with GVL unlocked
checking for pg_config... no
checking for libpq per pkg-config... no
Using libpq from 
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*****************************************************************************

Unable to find PostgreSQL client library.

Please install libpq or postgresql client package like so:
  sudo apt install libpq-dev
  sudo yum install postgresql-devel
  sudo zypper in postgresql-devel
  sudo pacman -S postgresql-libs

or try again with:
  gem install pg -- --with-pg-config=/path/to/pg_config

or set library paths manually with:
  gem install pg -- --with-pg-include=/path/to/libpq-fe.h/ --with-pg-lib=/path/to/libpq.so/

*** 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.

    中略

An error occurred while installing pg (1.4.5), and Bundler cannot continue.
Make sure that `gem install pg -v '1.4.5' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  pg

解決した方法

①Gemfileで、「gem 'pg'」の記述を完全削除する

②Gemfile.lockを削除、ローカル環境でbundle installをおこなう

③GitHubにコミットとプッシュ

④EC2環境でgit pull origin master

⑤EC2環境でbundle install

これで無事インストールできました。

原因

今回、AWSに移行するにあたってDBは「MariaDB」を使うので「postgreSQL」のGemであるpgがあることでエラーが発生していたようです。

あとがき

よくよく考えれば当たり前のようなことですが、勉強不足でそこまで気がまわっていませんでした。
サーバー周りは特に知識不足なのでよく考えて実装していきたいと思います。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2