Ruby on Rails – Error installing mysql2: Failed to build gem native extension – Ubuntu Linux

      This is a very common issue where we get error “Error installing mysql2: Failed to build gem native extension” while installing mysql2 gem in Rails(in Ubuntu Linux OS). The problem is due to missing libmysql(from MYSQL) file.

Linux Solution:

      To solve the issue install the compnents libmysql-ruby and libmysqlclient-dev using the command sudo apt-get install libmysql-ruby libmysqlclient-dev (Run in Ubuntu Terminal). Then run gem install mysql2 which should run successfully.

Windows Solution:

      Run the following command where we pass the location of MYSQL lib and include folder. Replace the PATH with the actual location of MYSQL Server application.

gem install mysql2 — ‘–with-mysql-lib=”PATH\MySQL Server 5.5\lib” –with-mysql-include=”PATH\MySQL Server 5.5\include”‘

Leave a Reply