rails bundle install時エラー「An error occurred while installing sqlite3 (x.x.x), and Bundler cannot continue.」の対処法

rails  bundle install時エラー「An error occurred while installing sqlite3 (x.x.x), and Bundler cannot continue.」の対処法

rails環境構築時にbundle installコマンド実行でエラー「-An error occurred while installing sqlite3 (x.x.x), and Bundler cannot continue.」が発生した場合の対処法を記述してます。

環境

  • OS CentOS Linux release 7.9.2009 (Core)
  • Ruby 2.7.2
  • Rails 6.1.1
  • rbenv 1.1.2-40-g62d7798

エラー全文

bundle install時に発生

 bundle install

エラー全文

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

    current directory: /home/user/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/sqlite3-1.4.2/ext/sqlite3
/home/user/.rbenv/versions/2.7.2/bin/ruby -I /home/user/.rbenv/versions/2.7.2/lib/ruby/site_ruby/2.7.0 -r ./siteconf20210113-6631-c2h0r8.rb
extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Try 'brew install sqlite3',
'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
and check your shared library search path (the
location where your sqlite3 shared library is located).
*** 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.4.2), and Bundler cannot continue.
Make sure that `gem install sqlite3 -v '1.4.2' --source 'https://rubygems.org/'` succeeds before bundling.

対処法

エラーメッセージ通りは、「sqlite-devel」をインストールすることで解決しました。

sudo yum install sqlite-devel