An error occurred while installing mysql2 (0.5.3), and Bundler cannot continue

Viewed 641

I am in apple M1 mac os 12.1 I have successfully install mysql2 with the command

gem install mysql2 -v '0.5.3' -- \
--with-mysql-lib=/opt/homebrew/Cellar/mysql/8.0.28/lib \
--with-mysql-dir=/opt/homebrew/Cellar/mysql/8.0.28 \
--with-mysql-config=/opt/homebrew/Cellar/mysql/8.0.28/bin/mysql_config \
--with-mysql-include=/opt/homebrew/Cellar/mysql/8.0.28/include

Successfully installed mysql2-0.5.3
Parsing documentation for mysql2-0.5.3
Done installing documentation for mysql2 after 0 seconds
1 gem installed

and when run bundle install I still got the error

linking shared-object mysql2/mysql2.bundle
ld: warning: directory not found for option '-L/opt/homebrew/Cellar/mysql/8.0.28/lib --with-mysql-dir=/opt/homebrew/Cellar/mysql/8.0.28
--with-mysql-config=/opt/homebrew/Cellar/mysql/8.0.28/bin/mysql_config --with-mysql-include=/opt/homebrew/Cellar/mysql/8.0.28/include'
ld: library not found for -lzstd
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1

An error occurred while installing mysql2 (0.5.3), and Bundler cannot continue. Make sure that gem install mysql2 -v '0.5.3' succeeds before bundling.

2 Answers

I had the same error with M1 mac and tried those commands below.

$ brew install openssl
$ echo 'export PATH="/opt/homebrew/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc
$ source ~/.zshrc
$ bundle config --local build.mysql2 "--with-ldflags=-L/opt/homebrew/opt/openssl@1.1/lib"
$ export LIBRARY_PATH=$LIBRARY_PATH:/opt/homebrew/Cellar/zstd/1.5.2/lib:/opt/homebrew/Cellar/openssl@1.1/1.1.1m/lib/

github

Run this command:-

$ sudo apt-get install default-libmysqlclient-dev

Related