Fixing the Error "Failed to Build Gem Native Extension" for MySQL2 Installation
When attempting to install the MySQL2 gem for Rails, you may encounter an error stating "Error installing mysql2: ERROR: Failed to build gem native extension." To resolve this issue and successfully install MySQL2, follow these steps:
For Ubuntu/Debian:
Run the following command to install the necessary dependencies:
sudo apt-get install libmysql-ruby libmysqlclient-dev
If libmysql-ruby cannot be found:
Install the libmysqlclient-dev package instead:
sudo apt-get install libmysqlclient-dev
For Red Hat/CentOS:
Install mysql-devel:
sudo yum install mysql-devel
For Mac OS X with Homebrew:
Install MySQL using Homebrew:
brew install mysql
By installing the appropriate dependencies for your operating system, you should now be able to successfully install the MySQL2 gem.
The above is the detailed content of How to Fix the 'Failed to Build Gem Native Extension' Error During MySQL2 Installation?. For more information, please follow other related articles on the PHP Chinese website!