ld: library not found for -lzstd while bundle install for mysql2 gem Ruby on macOS Big Sur 11.4 Apple M1
Step 1:
confirm you have both openssl and MySQL installed via brew
brew install mysql
brew install openssl
or if you have previous version of openssl try
brew reinstall openssl@3
Step 2:
Run this on your Rails app to make sure you can get through bundler:
gem install mysql2 -v '0.5.3' -- --with-opt-dir=$(brew --prefix openssl) --with-ldflags=-L/opt/homebrew/opt/zstd/lib
two things to note: $(brew --prefix openssl)
dynamically replaces the stuff inside the evaluation $(...)
to the directory of openssl on your machine.
/opt/homebrew/opt/zstd
is really a symlink to the current version of zstd on your machine (which links to something like /opt/homebrew/opt/Cellar/zstd/1.5.2
)
Step 3:
If you want this globally, run this:
bundle config --global build.mysql2 "--with-opt-dir=$(brew --prefix openssl) --with-ldflags=-L/opt/homebrew/opt/zstd/lib"
note that this will change your ~/.bundler/config
file and then applies globally to bundler
An error occurred while installing mysql2 (0.4.8), and Bundler cannot continue
I think you missing dev library of mysql:
On ubuntu
sudo apt-get install libmysqlclient-dev
On Red Hat/CentOS and other distributions using yum:
sudo yum install mysql-devel
On Mac OS X with Homebrew:
brew install mysql
Installing mysql2 gem for Ruby on Rails with Mac OSX 10.6
It seems that it cannot find the MySQL library. Have you installed MySQL?
Try installing it via homebrew:
brew install mysql
or install it via macports or fink or whatever you prefer.
Then try again with:
gem install mysql2
Related Topics
How to Use Functions Like Concat(), etc. in Arel
Ruby Indented Multiline Strings
How to Fix an Accidental 'Sudo Bundle Install Dir_Name'
Using Compass from Ruby (Not Shell)
How to Click on a Specific Coordinates of an Element
How to Convert a Ruby String with Brackets to an Array
How to Stringize/Serialize Ruby Code
Make Rails Ignore Daylight Saving Time When Displaying a Date
Rails 4 How to Call Accessible_Attributes from Model
How to Convert Ppt to Images in Ruby
"Msvcrt-Ruby18.Dll Was Not Found" with Ruby
How to Read Files in an Eventmachine-Based App
Rails 5 Db Migration: How to Fix Activerecord::Concurrentmigrationerror
How to Give a Sub-Module the Same Name as a Top-Level Class