Home >Database >Mysql Tutorial >How to Fix 'Error installing mysql2: Failed to build gem native extension' in Ruby?
Resolving "Error installing mysql2: Failed to build gem native extension" Issue in Ruby
Installing the mysql2 gem for Rails can be a hassle at times, leading to the infamous "Error installing mysql2: ERROR: Failed to build gem native extension" error. To rectify this issue, follow the steps outlined below:
Ubuntu/Debian
For distributions utilizing aptitude, execute the following command:
sudo apt-get install libmysql-ruby libmysqlclient-dev
Note that libmysql-ruby is being replaced by ruby-mysql, as per the solution found online. If the previous command fails due to libmysql-ruby's absence, try this alternative:
sudo apt-get install libmysqlclient-dev
Red Hat/CentOS
For systems utilizing yum, run the following command:
sudo yum install mysql-devel
Mac OS X
If you're working on macOS with Homebrew, execute this command:
brew install mysql
After following the appropriate steps, you should be able to successfully install mysql2 and proceed with your Ruby on Rails endeavors.
The above is the detailed content of How to Fix 'Error installing mysql2: Failed to build gem native extension' in Ruby?. For more information, please follow other related articles on the PHP Chinese website!