はじめに
Railsでbundle intall実行時に出るエラーの対応方法です。
コンソールの末尾には下記のように表示されました。
An error occurred while installing sqlite3 (1.6.3), and Bundler cannot continue.
内容
環境
- macOS 13.4
- Apple M1
- Ruby 3.2.0
- Bundler version 2.4.18
- asdf v0.13.1
解決方法
-
brew install pkg-config
を実行してから -
bundle install
を再度実行
原因
エラーメッセージを添付します。
$ bundle install
...省略...
Building sqlite3-ruby using packaged sqlite3.
Extracting sqlite-autoconf-3420000.tar.gz into tmp/arm64-apple-darwin22.5.0/ports/sqlite3/3.42.0... OK
Running 'configure' for sqlite3 3.42.0... OK
Running 'compile' for sqlite3 3.42.0... OK
Running 'install' for sqlite3 3.42.0... OK
Activating sqlite3 3.42.0 (from /Users/takuzo/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/sqlite3-1.6.3/ports/arm64-apple-darwin22.5.0/sqlite3/3.42.0)...
Could not configure the build properly (pkg_config). Please install either the `pkg-config` utility or the `pkg-config` rubygem.
*** 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 sqlite3 (1.6.3), and Bundler cannot continue.
In Gemfile:
sqlite3
ポイントは下記ですね。
Could not configure the build properly (pkg_config). Please install either the
pkg-config
utility or thepkg-config
rubygem.
ビルドを適切に構成できないからpkg_configを入れてくれとのことでした。
gemを入れてみたのですが上手く動かず、homebrewでインストールしたら上手く動きました。
補足:pkg_configとは
pkg-configとは、ライブラリを利用する際に必要となる各種フラグやパス等を、共通したインターフェースで提供でするための手段である。
ビルド時に必要なライブラリやヘッダの所在などの情報を環境変数から取得する仕組みです。
今回はこれがなかったためにMakefileが作れずインストールに失敗していました。
参考
下記を参考にさせていただきました。