このセクションでは、Redmine 環境の構築中に発生した “ An error occurred while installing mysql2 (0.5.5), and Bundler cannot ” への対処について紹介していきます。

[user@pub-web]$ sudo bundle install --path vendor/bundler --without development test

ーー(省略)ーー
An error occurred while installing mysql2 (0.5.5), and Bundler cannot
continue.

In Gemfile:
  mysql2
[yuji@pub-web]$ 

この警告は、MariaDB 環境で Redmine 環境を構築している段階で発生しました。

[原因]
mariadb に関する必要なパッケージが事前にインストールされていないことが原因

[確認]
mariadb-connector-c-devel のパッケージがインストールされているかどうかを確認します。インストールされていなければ、下記の[ 対処 ]を実行します。

[user@almalinux ~]$ sudo dnf list mariadb-connector-c-devel
Last metadata expiration check: 2:49:25 ago on Wed Aug 30 01:53:05 2023.
Available Packages
mariadb-connector-c-devel.i686               3.2.6-1.el9_0             appstream
mariadb-connector-c-devel.x86_64             3.2.6-1.el9_0             appstream
[user@almalinux ~]$ 

[対処]
mariadb-connector-c-devel のパッケージをインストールします。

[user@pub-web redmine]$ sudo dnf install mariadb-connector-c-devel
Last metadata expiration check: 1:01:47 ago on Mon Aug 28 03:18:24 2023.
Dependencies resolved.
================================================================================
 Package                       Arch       Version           Repository     Size
================================================================================
Installing:
 mariadb-connector-c-devel     x86_64     3.2.6-1.el9_0     appstream      55 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 55 k
Installed size: 184 k
Is this ok [y/N]: y
Downloading Packages:
mariadb-connector-c-devel-3.2.6-1.el9_0.x86_64. 272 kB/s |  55 kB     00:00    
--------------------------------------------------------------------------------
Total                                            57 kB/s |  55 kB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Installing       : mariadb-connector-c-devel-3.2.6-1.el9_0.x86_64         1/1 
  Running scriptlet: mariadb-connector-c-devel-3.2.6-1.el9_0.x86_64         1/1 
  Verifying        : mariadb-connector-c-devel-3.2.6-1.el9_0.x86_64         1/1 

Installed:
  mariadb-connector-c-devel-3.2.6-1.el9_0.x86_64                                

Complete!
[user@pub-web redmine]$ 

対処後に正常であれば、下記のようにエラーなくコマンド実行は終了します。解決されない場合には、別の要因の可能性がありますので別の視点での調査が必要です。

[user@pub-web redmine]$ sudo bundle install --path vendor/bundler --without development test
[DEPRECATED] The `--path` flag is deprecated because it relies on being remembered across bundler invocations, which bundler will no longer do in future versions. Instead please use `bundle config set --local path 'vendor/bundler'`, and stop using this flag
[DEPRECATED] The `--without` flag is deprecated because it relies on being remembered across bundler invocations, which bundler will no longer do in future versions. Instead please use `bundle config set --local without 'development test'`, and stop using this flag
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and
installing your bundle as root will break this application for all non-root
users on this machine.
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies.....
Using rake 13.0.6
ーー(省略)ーー

Using activestorage 6.1.7.2
Using actionmailer 6.1.7.2
Using railties 6.1.7.2
Using sprockets-rails 3.4.2
Using actionmailbox 6.1.7.2
Using actiontext 6.1.7.2
Using actionpack-xml_parser 2.0.1
Using roadie-rails 3.0.0
Using rails 6.1.7.2
Bundle complete! 43 Gemfile dependencies, 74 gems now installed.
Gems in the groups 'development' and 'test' were not installed.
Bundled gems are installed into `./vendor/bundler`
[user@pub-web redmine]$