單純地使用
gem install mysql2
安裝會有library 'zstd' not found的 error
linking shared-object mysql2/mysql2.bundle
ld: library 'zstd' not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/sung/.asdf/installs/ruby/2.5.9/lib/ruby/gems/2.5.0/gems/mysql2-0.5.5 for inspection.
Results logged to /Users/sung/.asdf/installs/ruby/2.5.9/lib/ruby/gems/2.5.0/extensions/-darwin-23/2.5.0/mysql2-0.5.5/gem_make.out
stackoverflow 這篇提到
while running bundle install
An error occurred while installing mysql2 (0.5.3), and Bundler cannot continue
Make sure that `gem install mysql2 -v '0.5.3' --source 'https://rubygems.org/'` succeeds before bundling.
Rails app 6.1.3
Bundler version 2.2.19
macOS Big Sur 11.4
Apple M1
in the Gemfile
ruby '2.6.6'
gem 'rails', '~> 6.1.3', '>=
…
在安裝要特地指名 openssl 和 zstd。
指令如下:
gem install mysql2 -v '0.5.5' -- --with-opt-dir=$(brew --prefix openssl) --with-ldflags=-L/opt/homebrew/opt/zstd/lib
這樣就成功啦~~~
gem install mysql2 -v '0.5.5' -- --with-opt-dir=$(brew --prefix openssl) --with-ldflags=-L/opt/homebrew/opt/zstd/lib
Building native extensions with: '--with-opt-dir=/opt/homebrew/opt/openssl@3 --with-ldflags=-L/opt/homebrew/opt/zstd/lib'
This could take a while...
Successfully installed mysql2-0.5.5
Parsing documentation for mysql2-0.5.5
Installing ri documentation for mysql2-0.5.5
Done installing documentation for mysql2 after 0 seconds
1 gem installed
Top comments (1)
Had same problem today
This worked for me
BUNDLE_BUILD__MYSQL2="--with-mysql-lib=/opt/homebrew/opt/mysql/lib --with-mysql-dir=/opt/homebrew/opt/mysql --with-mysql-config=/opt/homebrew/opt/mysql/bin/mysql_config \ --with-mysql-include=/opt/homebrew/opt/mysql/include --with-ldflags=-L/opt/homebrew/opt/zlib/lib" bundle