redmine 安装失败,ruby 3.0.4,mysql2 (0.5.4) "undefined method 'split'" "rb_enc_interned_str not found"

redmine install failure, ruby 3.0.4, mysql2 (0.5.4) "undefined method 'split'" "rb_enc_interned_str not found"

构建新系统:

  ubuntu 20.04
  mysql 5.7.38
  ruby-install and chruby
    ruby 3.0.4
  redmine 5.0.0

在用户帐户中,尝试安装 redmine 5.0.0:

bundle install
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory: /home/test_user/.gem/ruby/3.0.4/gems/mysql2-0.5.4/ext/mysql2
/opt/rubies/ruby-3.0.4/bin/ruby -I /opt/rubies/ruby-3.0.4/lib/ruby/3.0.0 -r ./siteconf20220520-28025-uxnsbe.rb
extconf.rb
...
*** 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.
Provided configuration options:
...
/opt/rubies/ruby-3.0.4/lib/ruby/3.0.0/mkmf.rb:1050:in `block in find_library': undefined method `split' for
nil:NilClass (NoMethodError)
 ...

查看日志,发现如下错误:

conftest.c: In function ‘t’:
conftest.c:14:57: error: ‘rb_wait_for_single_fd’ undeclared (first use in this function)
   14 | int t(void) { void ((*volatile p)()); p = (void ((*)()))rb_wait_for_single_fd; return !p; }

conftest.c: In function ‘t’:
conftest.c:16:57: error: ‘rb_enc_interned_str’ undeclared (first use in this function); did you mean ‘rb_interned_str’?
   16 | int t(void) { void ((*volatile p)()); p = (void ((*)()))rb_enc_interned_str; return !p; }

我安装了以下 mysql 东西:

$ apt list --installed | grep mysql
libmysqlclient20/unknown,now 5.7.38-1ubuntu18.04 amd64 [installed]
mysql-apt-config/unknown,now 0.8.22-1 all [installed]
mysql-client/unknown,now 5.7.38-1ubuntu18.04 amd64 [installed,upgradable to: 8.0.29-0ubuntu0.20.04.3]
mysql-common/focal,now 5.8+1.0.5ubuntu2 all [installed,automatic]
mysql-community-client/unknown,now 5.7.38-1ubuntu18.04 amd64 [installed,automatic]
mysql-community-server/unknown,now 5.7.38-1ubuntu18.04 amd64 [installed]
mysql-server/unknown,now 5.7.38-1ubuntu18.04 amd64 [installed,upgradable to: 8.0.29-0ubuntu0.20.04.3]

我有点糊涂; ruby 安装(mkmf.rb,无方法 'split')和 redmine 代码(未声明的函数)报告了错误。

我意识到这是一个新的 ruby 和一个新的 redmine,以及一个旧的 mysql;不确定这是否是问题所在。我想坚持使用 mysql 5.7 以避免升级我现在需要迁移的数据。

您缺少 MySQL 开发包之一。对于其他绊倒这个问题的候选人是:

default-libmysqld-dev 
default-libmysqlclient-dev

或者有时直接打包:

libmysqld-dev 
libmysqlclient-dev

在这种特殊情况下,结果是 default-libmysqlclient-dev