MySQL Install on Mac: Resolving "ERROR: Failed to build gem native extension"
When attempting to install MySQL using the command gem install mysql, users may encounter the error "ERROR: Failed to build gem native extension." This issue is commonly faced when the system lacks the necessary headers and libraries for building the native extensions.
To address this issue, follow these steps:
-
Verify MySQL Client Library Installation: Ensure that the MySQL client library is installed. On Debian (or Ubuntu) systems, execute sudo apt-get install libmysqlclient-dev.
-
Confirm Xcode Tools: macOS Catalina and later require Xcode command-line tools for successful installation. If you receive "checking for mysql_query() in -lmysqlclient... no" errors, consider reinstalling Xcode command-line tools.
-
Check Header Files: Ensure that header files for Ruby are present at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h. If not, try reinstalling Ruby.
-
Path Permissions: Verify that paths in /usr/bin have appropriate permissions. Edit extconf.rb and add ENV['PATH'] = "/usr/bin:/usr/sbin:$PATH" before require "mkmf".
-
Additional Troubleshooting: For systems running macOS Mojave or earlier, try running export MACOSX_DEPLOYMENT_TARGET=10.9 before executing gem install mysql.
After implementing these steps, rerun gem install mysql. If the issue persists, you may need to refer to the gem_make.out log located at /Library/Ruby/Gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out for further debugging.
The above is the detailed content of How to Fix \"ERROR: Failed to build gem native extension\" When Installing MySQL on Mac?. For more information, please follow other related articles on the PHP Chinese website!
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn