1.情况1: "bundle install" command or "gem install mysql2" it gives me following error "Error installing mysql2: ERROR: Failed to build gem native extension."
解决方案: sudo apt-get install libmysql-ruby libmysqlclient-dev
gem install mysql2
2.情况2: 安装mysql时候 改变了安装目录,
checking for mysql_query() in -lmysqlclient... no > checking for main() in -lm... yes > checking for mysql_query() in -lmysqlclient... no > checking for main() in -lz... yes > checking for mysql_query() in -lmysqlclient... no > checking for main() in -lsocket... no > checking for mysql_query() in -lmysqlclient... no > checking for main() in -lnsl... yes > checking for mysql_query() in -lmysqlclient... no > extconf.rb failed > Could not create Makefile due to some reason, probably lack of > necessary libraries and/or headers. Check the mkmf.log file for more > details. You may need configuration options.
解决方案:sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
http://zool.it/posts/gem-install-mysql2-error
3. 以上两种组合