You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过bundle install安装mysql2 gem时添加编译参数失败求助

解决mysql2 gem通过Bundle安装失败的问题

问题原因

你之前执行的bundle config命令格式错误,额外添加了-v '0.4.10'参数,导致编译配置未被正确识别。从错误日志能看到,Bundle实际使用了默认的OpenSSL路径(/usr/local/opt/openssl),而非你指定的openssl@1.1路径,最终引发编译失败。

解决方案

方法1:修正Bundle全局配置

  1. 先清除错误的配置:
bundle config unset build.mysql2
  1. 重新设置正确的编译参数(gem版本无需在这里指定,直接在Gemfile中定义即可):
bundle config build.mysql2 "--with-cflags=-I/usr/local/opt/openssl@1.1/include --with-ldflags=-L/usr/local/opt/openssl@1.1/lib"
  1. 执行Bundle安装:
bundle install

方法2:在Gemfile中直接指定编译参数

如果不想全局配置Bundle,也可以在项目的Gemfile里直接为mysql2指定编译选项:

gem 'mysql2', '0.4.10', build: [
  "--with-cflags=-I/usr/local/opt/openssl@1.1/include",
  "--with-ldflags=-L/usr/local/opt/openssl@1.1/lib"
]

保存后执行bundle install即可。

内容的提问来源于stack exchange,提问作者opensource-developer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 00:12:06