首页 > 解决方案 > Apple Silicon 上的 Rails 和 MySQL

问题描述

有没有人能够通过 Apple Silicon 上的 mysql2 gem 让 Rails 与 MySQL 一起运行?我正在使用 Ruby 2.5.3 和 Rails 5.2.3,但很想听到任何版本的成功。目前,我遇到了 mysql2 gem install 失败的问题:

linking shared-object mysql2/mysql2.bundle
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1

谢谢!

标签: mysqlruby-on-railshomebrewmysql2apple-silicon

解决方案


我在以下方面取得了成功:

rbenv exec gem install mysql2 -- \
--with-mysql-lib=/opt/homebrew/Cellar/mysql/8.0.25_1/lib \
--with-mysql-dir=/opt/homebrew/Cellar/mysql/8.0.25_1 \
--with-mysql-config=/opt/homebrew/Cellar/mysql/8.0.25_1/bin/mysql_config \
--with-mysql-include=/opt/homebrew/Cellar/mysql/8.0.25_1/include 

(请注意,您可能需要更改这些路径中的版本号)

值得注意的是,这适用于最新版本的 mysql,不需要任何 Intel 版本或使用 HomeBrew 的模拟版本(例如ibrew)。

将 Bundler 配置为自动使用此构建配置:

您可能还想将此配置设置为mysql2. 这样,无论何时 bundler 必须重新安装mysql2(在此项目或同一台计算机上的任何其他项目上),它都会自动使用此配置。您可以通过以下方式做到这一点:

bundle config set --global build.mysql2 \
--with-mysql-lib=/opt/homebrew/Cellar/mysql/8.0.25_1/lib \
--with-mysql-dir=/opt/homebrew/Cellar/mysql/8.0.25_1 \
--with-mysql-config=/opt/homebrew/Cellar/mysql/8.0.25_1/bin/mysql_config \
--with-mysql-include=/opt/homebrew/Cellar/mysql/8.0.25_1/include 

推荐阅读