解決 gem install mysql2 時遇到 'zstd' not found 錯誤的問題

fredwusong

FRedwuSong

Posted on December 12, 2023

解決 gem install mysql2 時遇到 'zstd' not found 錯誤的問題

單純地使用

gem install mysql2
Enter fullscreen mode Exit fullscreen mode

安裝會有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
Enter fullscreen mode Exit fullscreen mode

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', '>=

在安裝要特地指名 opensslzstd

指令如下:

gem install mysql2 -v '0.5.5' -- --with-opt-dir=$(brew --prefix openssl) --with-ldflags=-L/opt/homebrew/opt/zstd/lib
Enter fullscreen mode Exit fullscreen mode

這樣就成功啦~~~

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
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
fredwusong
FRedwuSong

Posted on December 12, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related