Cannot Install "mysql gem" on MacOS Sierra - mysql

I am trying to install the mysql2 gem for one of my rails projects but I am getting an error. I run this command:
gem install mysql2
The error says:
ld: library not found for -lssl
However when I run:
brew install openssl
I get (which proves that I have the -lssl library):
Error: openssl-1.0.2f already installed
To install this version, first `brew unlink openssl`
And alternatively when I run (which proves I have mysql on my machine):
brew install mysql
I get:
Error: mysql-5.7.10 already installed
To install this version, first `brew unlink mysql`
Very lost and would love to solve this, thank you in advance. I am running brew version 1.0.4.

I am having the same problem on Mac OS Mojave.
The following worked for me. First – very important – I ran xcode and discovered it needed to install some crap again. Then I did
brew reinstall openssl
gem install mysql2 -v '0.4.5' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
bundle install
The second line is based on the answer here.

I solved the same issue on my MacOS Sierra by refreshing gems reference:
gem source -r https://rubygems.org/
gem source -a https://rubygems.org/

Related

Unable to locate package libmysqlclient-dev

ruby 2.6.3
Ubuntu 16.04
Unable to locate package libmysqlclient-dev
description:
Fetching mysql2 0.5.2
Installing mysql2 0.5.2 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
To solve this I ran following.
gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/'
Then got the following error.
mysql client is missing. You may need to 'apt-get install libmysqlclient-dev'
now I am stuck and found no solution working. tried google and all other option but no suggestion is working for me.
Unable to locate package libmysqlclient-dev
To give you proper answer as I found that all comments are to the point, but I wanted to check if really such issue exists. So I spin up new ubuntu server 16.04 and used following commands to installd mysql gem. I used rvm to install ruby
sudo apt-get update
sudo apt-get install mysql-server
sudo apt-get install software-properties-common
sudo apt-add-repository -y ppa:rael-gc/rvm
sudo apt-get update
sudo apt-get install rvm
Now relogin to terminal to rvm command can start with its environment
rvm install ruby 2.6.3
Now I used ruby -version to check I am using same version as you were so got response ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux] Now I used following command to install gem. If it succeed then rails will be also installed.
gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/'
But I am getting same error as yours, now let us solve it as it is saying us how to solve error. This error is already giving me information what should I do. It told me to install following package
apt-get install libmysqlclient-dev
And now I tried again and it worked. Hope it will resolve your issue. If you still have issue, than you can try by removing mysql packages you install and reinstall using these commands.

Create a symlink for the libmysqlclient.18.dylib library

I have installed mysql through a pkg installer.
I am trying to start rails server and I am getting the following error.
Library not loaded: libmysqlclient.18.dylib (LoadError)
I am reading that a solution to that is to create a symlink like
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
There is no
/usr/local/mysql/lib/libmysqlclient.18.dylib
file only a
/usr/local/mysql/lib/libmysqlclient.20.dylib file.
I run
sudo find /usr/ -name libmysqlclient.18.dylib
and I can't find the libmysqlclient.18.dylib file.
I encountered a problem like this while setting up a new development environment. I had installed MySQL via homebrew, which gave me version 5.7.9 of MySQL, with the library version libmysqlclient.20.dylib.
In my case, I was setting up a python project. The requirements install failed because the python-MySQL connection piece was looking for libmysqlclient.18.dylib, which was nowhere to be found on my machine.
Downgrading to MySQL 5.6 solved the issue for me:
brew uninstall mysql
brew tap caskroom/versions
brew install mysql56
Now /usr/local/lib/libmysqlclient.18.dylib is present and everything's peachy.
The mysql2 gem which is most likely in your Rails environment is still looking for libmysqlclient.18.dylib (from what must have been a previous mysql install) but the library is no longer there because the recent manual install/upgrade replaced it with libmysqlclient.20.dylib.
The easy fix is to install again mysql2:
gem uninstall mysql2 && gem install mysql2
or better yet:
gem uninstall mysql2 && bundle, if you are on Bundler.
I did not have mysql installed through brew or gem, and was facing the same issue that it was looking for libmysqlclient.18.dylib instead of libmysqlclient.20.dylib. I tried everything mentioned here and at some other threads. Nothing worked. Finally, this worked for me:
pip install mysqlclient
It does not install libmysqlclient.18.dylib, but solves the library not installed and image not found errors.
Hope it helps someone!
Uninstall mysqlclient
Clear cache of your pip
Find folder in which pip wheel cache is stored for mysqlclient and delete it.
Reinstall mysqlclient
mac mojave OS cache will be in this folder: ~/Library/Caches/pip. Follow the steps below:
Find ~/Library/Caches/pips/wheels/ | grep mysql
Delete the file you got.
pip install mysqlclient

Error when trying to install app with mysql2 gem

Im trying to install an open source rails 3.2.21 application that uses the mysql2 gem, but when i try and run the bundle commant I get the following error:
Fetching: mysql2-0.3.18.gem (100%)
Building native extensions. This could take a while...
p
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/Users/my_username/.rvm/rubies/ruby-2.1.2/bin/ruby -r ./siteconf20150614-72129-orqsb7.rb extconf.rb
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
-----
Using mysql_config at /usr/local/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
-----
Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
-----
-----
Setting libpath to /usr/local/Cellar/mysql/5.6.25/lib
-----
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
compiling client.c
compiling infile.c
compiling mysql2_ext.c
compiling result.c
linking shared-object mysql2/mysql2.bundle
ld: warning: directory not found for option '-L/Users/travis/.sm/pkg/active/lib'
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/my_username/.rvm/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/mysql2-0.3.18 for inspection.
Results logged to /Users/my_username/.rvm/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/extensions/x86
I tried uninstalling every version of mysql I installed via homebrew and reinstalling them, like so:
brew uninstall --force mysql && brew install mysql
Then running:
sudo gem install mysql2
As suggested by a number of similar questions asked on here, but it still results in the same error as above.
Please could someone offer guidance on how to get this up and running?
For anybody still experiencing the issue:
When you install openssl via brew, you should get the following message:
Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries
Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:
LDFLAGS: -L/usr/local/opt/openssl/lib
CPPFLAGS: -I/usr/local/opt/openssl/include
PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig
You can set these build flags (for the local application) by running the following:
bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"
This worked for me.
See bundler's documentation for more information.
The error log says:
ld: library not found for -lssl
So, you need to install libssl:
brew install openssl
As it was pointed out in comments, there might be a need to export the path to the library.
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
Try this:
gem install mysql2 -v '0.5.2' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
(Update version as appropriate)
The solution for me was to install the Xcode Command Line Tools.
I had recently updated Xcode through the Mac App Store, and every time I do that, I've found that I have to reinstall the Command Line Tools again.
xcode-select --install
Based on the solution here
brew install openssl
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
solved the problem.
After Homebrew update (openssl#1.1) there is a new path for libs, so may use:
bundle config build.mysql2 --with-opt-dir=$(brew --prefix openssl)
bundle install
It will fix ld: library not found for -lssl error
Thanks #mudasobwa for pointing me in the right direction. It turns out the error was caused by an unlinked openssl file, so running:
brew reinstall openssl && brew link openssl --force
Solved the problem. I found the solution here: OpenSSL, RVM, Brew, conflicting error
On MacBook air M1(macOS) it worked for me.
Install zstd
brew install zstd
Install mysql2
gem install mysql2 -v '0.5.3' -- --with-opt-dir=$(brew --prefix openssl) --with-ldflags=-L/opt/homebrew/Cellar/zstd/1.5.0/lib
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
From here:
https://gorails.com/setup/osx/10.14-mojave
The combination of commands solved it me. I am on Mojave.
brew reinstall openssl && brew link openssl --force
and then
gem install mysql2 -v '0.4.10' -- \
--with-ldflags=-L/usr/local/opt/openssl/lib \
--with-cppflags=-I/usr/local/opt/openssl/include
Steps for me on Monterey M1 Mac
brew install openssl#3
brew install zstd
gem install mysql2 -v '0.5.3' -- --with-opt-dir=$(brew --prefix openssl) --with-ldflags=-L/opt/homebrew/Cellar/zstd/1.5.0/lib
bundle config --local build.mysql2 "--with-opt-dir=$(brew --prefix openssl) --with-ldflags=-L/opt/homebrew/Cellar/zstd/1.5.0/lib"
bundle install
Seems that you miss the main files needed to build mysql2 gem
sudo apt-get install libsqlite3-dev libmysqlclient-dev -y
libsqlite3-dev is not mandatory but install it since it's the default rails DB.
Mac Catalina using Homebrew fix:
gem install mysql2 -- --with-opt-dir="$(brew --prefix openssl)"
the following command works for my Mac os 12.1 MacOs Monterey
gem install mysql2 -v '0.5.3' -- \
--with-mysql-lib=/opt/homebrew/Cellar/mysql/8.0.28/lib \
--with-mysql-dir=/opt/homebrew/Cellar/mysql/8.0.28 \
--with-mysql-config=/opt/homebrew/Cellar/mysql/8.0.28/bin/mysql_config \
--with-mysql-include=/opt/homebrew/Cellar/mysql/8.0.28/include
Please refer this link for more details
https://github.com/brianmario/mysql2/issues/1175
This finally worked for me on macOS Monterey 12.3 (M1 Pro):
gem install mysql2 -- --with-mysql-dir=/opt/homebrew/Cellar/mysql/8.0.28_1
Make sure you read the installation instructions. Notable points for me were:
Make sure MySQL is installed (brew install mysql)
Make sure XCode select tools are installed (xcode-select --install)
Set the with-mysql-dir option to wherever mysql was installed (check with brew info mysql)
Combining the answers given by Aleksei Matiushkin and Alexey Mozorov fixed the problem for me.
But I also updated the openssl before adding the path.
Thanks!
I've been coding with mysql2 gem for years and have encountered with this issue time to time.
Today I found that this magic option -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include no longer worked on my Mac. Indeed, it looks like the default location where brew installs openssl has changed:
$ brew reinstall openssl
...
If you need to have openssl#3 first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/openssl#3/bin:$PATH"' >> ~/.zshrc
For compilers to find openssl#3 you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/openssl#3/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl#3/include"
So following the message, I had to make a few changes to the command and got it work finally:
$ gem install mysql2 -v '0.5.3' -- --with-ldflags=-L/opt/homebrew/opt/openssl#3/lib --with-cppflags=-I/opt/homebrew/opt/openssl#3/include
Hope this will help someone!
This helped me on MacOs 12.6 (Monterey)
brew install mysql openssl
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
gem install mysql2 -v '0.5.3' \
--source 'https://rubygems.org/' -- \
--with-cppflags=-I/usr/local/opt/openssl/include \
--with-ldflags=-L/usr/local/opt/openssl/lib
bundle install
Thanks https://github.com/brianmario/mysql2/issues/1175#issuecomment-1069721834
I found that I had to use --with-opt-dir=/usr/local/opt.
Specifically, I added the following to my ~/.bundle/config file:
BUNDLE_BUILD__MYSQL2: "--with-opt-dir=/usr/local/opt"

Rails-MySQL Error - uninitialized constant MysqlCompat::MysqlRes

Trying to get a Rails app running on Snow Leopard.
Downloaded mysql-5.5.8-osx10.6-x86_64.dmg and ran installer
Ruby 1.8.7 (Default OS X version)
Rails 2.3.5
When I attempt to run "rake db:migrate" I get
rake aborted!
uninitialized constant MysqlCompat::MysqlRes
Yes I know this has been asked before. I have already reviewed the following links and followed the steps included in them and the result is the same each time.
Rails, MySQL and Snow Leopard
http://techliberty.blogspot.com/2009/12/dealing-with-rake-aborted-uninitialized.html
http://www.schmidp.com/2009/06/14/rubyrails-and-mysql-on-snow-leopard-10a380/
Prior to the following commands I run "sudo gem uninstall mysql" followed by "sudo gem clean mysql" based on the above links:
sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
It is still failing. I am just flumoxed and would greatly appreciate any help.
Many thanks!
Not had the experience myself and I'm using Snow Leopard, RVM and rails 2.3.5 to 3.0.3, but found another view which deals with the uninstall and reinstall via :
export ARCHFLAGS="-arch i386 -arch x86_64" ;sudo gem install --no-rdoc --no-ri -v=2.7 mysql -- --with-mysql-dir=/usr/local/mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config
For more details see the posting at: http://accidentaltechnologist.com/apple/fixing-uninitialized-constant-mysqlcompatmysqlres-error-on-snow-leopard/
For El Capitan you don't need to uninstall / install.
Just found your libmysqlclient.18.dylib file. Location will depent on how you installed mysql
locate libmysqlclient.18.dylib
Once you have the path create a symb link as:
ln -s /usr/local/mysql-5.5.20-osx10.6-x86_64/lib/libmysqlclient.18.dylib /usr/local/lib/libmysqlclient.18.dylib
You have two change first param according to your dynamic library location (use the first command).
On El Capitan the link should be to /usr/local/lib. On previous versions link was to /usr/lib/

Error installing mysql2: Failed to build gem native extension

I am having some problems when trying to install mysql2 gem for Rails. When I try to install it by running bundle install or gem install mysql2 it gives me the following error:
Error installing mysql2: ERROR: Failed to build gem native extension.
How can I fix this and successfully install mysql2?
On Ubuntu/Debian and other distributions using aptitude:
sudo apt-get install libmysql-ruby libmysqlclient-dev
Package libmysql-ruby has been phased out and replaced by ruby-mysql. This is where I found the solution.
If the above command doesn't work because libmysql-ruby cannot be found, the following should be sufficient:
sudo apt-get install libmysqlclient-dev
On Red Hat/CentOS and other distributions using yum:
sudo yum install mysql-devel
On Mac OS X with Homebrew:
brew install mysql
I'm on a mac and use homebrew to install open source programs. I did have to install mac Dev tools in order to install homebrew, but after that it was a simple:
brew install mysql
to install mysql. I haven't had a mysql gem problem since.
here is a solution for the windows users, hope it helps!
Using MySQL with Rails 3 on Windows
Install railsinstaller -> www.railsinstaller.org (I installed it to c:\Rails)
Install MySQL (I used MySQL 5.5) -> dev.mysql.com/downloads/installer/
--- for mySQL installation ---
If you dont already have these two files installed you might need them to get your MySQL going
vcredist_x86.exe -> http://www.microsoft.com/download/en/details.aspx?id=5555
dotNetFx40_Full_x86_x64.exe -> http://www.microsoft.com/download/en/details.aspx?id=17718
Use default install
Developer Machine
-MySQL Server Config-
port: 3306
windows service name: MySQL55
mysql root pass: root (you can change this later)
(username: root)
-MySQL Server Config-
--- for mySQL installation ---
--- Install the mysql2 Gem ---
Important: Do this with Git Bash Command Line(this was installed with railsinstaller) -> start/Git Bash
gem install mysql2 -- '--with-mysql-lib="c:\Program Files\MySQL\MySQL Server 5.5\lib" --with-mysql-include="c:\Program Files\MySQL\MySQL Server 5.5\include"'
Now the gem should have installed correctly
Lastly copy the libmysql.dll file from
C:\Program Files\MySQL\MySQL Server 5.5\lib
to
C:\Rails\Ruby1.9.2\bin
--- Install the mysql2 Gem ---
You will now be able to use your Rails app with MySQL, if you are not sure how to create a Rails 3 app with MySQL read on...
--- Get a Rails 3 app going with MySQL ---
Open command prompt(not Git Bash) -> start/cmd
Navigate to your folder (c:\Sites)
Create new rails app
rails new world
Delete the file c:\Sites\world\public\index.html
Edit the file c:\Sites\world\config\routes.rb
add this line -> root :to => 'cities#index'
Open command prompt (generate views and controllers)
rails generate scaffold city ID:integer Name:string CountryCode:string District:string Population:integer
Edit the file c:\Sites\world\app\models\city.rb to look like this
class City < ActiveRecord::Base
set_table_name "city"
end
Edit the file c:\Sites\world\config\database.yml to look like this
development:
adapter: mysql2
encoding: utf8
database: world
pool: 5
username: root
password: root
socket: /tmp/mysql.sock
add to gemfile
gem 'mysql2'
Open command prompt windows cmd, not Git Bash(run your app!)
Navigate to your app folder (c:\Sites\world)
rails s
Open your browser here -> http://localhost:3000
--- Get a Rails 3 app going with MySQL ---
For MacOS Mojave:
gem install mysql2 -v '0.5.2' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
On Ubuntu(18.04)
i was able to solve this issue by running the following:
sudo apt-get install build-essential libmysqlclient-dev
gem install mysql2
reference
Another way for MacOS users
If you used "brew" to install mysql:
gem install mysql2 -v 'x.x.x' -- --with-mysql-config=/usr/local/Cellar/mysql/y.y.y/bin/mysql_config
x.x.x = version of the mysql2 gem you want to install
y.y.y = the version of mysql you have installed ls /usr/local/Cellar/mysql to find it.
I have several computers, 32 and 64 bits processor, they run on Ubuntu Linux, Maverick (10.10) release.
I had the same problem, and for me, the
sudo apt-get install libmysql-ruby libmysqlclient-dev
did the job!!!
Have you tried using
gem install mysql -- --with-mysql-lib=/usr/lib/mysql/lib
to specify the location of thebase directory as well as the path to the MySQL libraries that are necessary to complete the gem installation?
Sources:
MySQL Gem Install ERROR: Failed to build gem native extension
MySQL Forums :: Ruby :: Help needed with installing MySQL binding for Ruby
If you are using yum try:
sudo yum install mysql-devel
This solved my problem once in Windows:
subst X: "C:\Program files\MySQL\MySQL Server 5.5"
gem install mysql2 -v 0.x.x --platform=ruby -- --with-mysql-dir=X: --with-mysql-lib=X:\lib\opt
subst X: /D
On Debian Stretch the package that worked for me was default-libmysqlclient-dev
sudo apt-get update && apt-get install -y default-libmysqlclient-dev
If you are still having trouble….
Try installing
sudo apt-get install ruby1.9.1-dev
In my case this helped:
$ export LDFLAGS="-L/usr/local/opt/openssl/lib"
$ export CPPFLAGS="-I/usr/local/opt/openssl/include"
Then:
gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/' -- --with-cppflags=-I/usr/local/opt/openssl/include --with-ldflags=-L/usr/local/opt/openssl/lib
Result:
Building native extensions with: '--with-cppflags=-I/usr/local/opt/openssl/include --with-ldflags=-L/usr/local/opt/openssl/lib'
This could take a while...
Successfully installed mysql2-0.5.2
Parsing documentation for mysql2-0.5.2
Installing ri documentation for mysql2-0.5.2
Done installing documentation for mysql2 after 0 seconds
1 gem installed
See this post (WARNING: Japanese language inside).
I had this issue on Windows 7. This is apparently an incompatibility issue and the solution is as follows:
Download the libmySQL.dll file from an older InstantRails installer. It is available from the InstantRails GitHub repo.
Next, copy that file into your Ruby/bin folder.
Now, you are good to go ;)
I got this error too. Solved by installing development packages. I'm using arch and it was:
sudo pacman -S base-devel
which installed:
m4, autoconf, automake, bison, fakeroot, flex, libmpc, ppl, cloog-ppl, elfutils, gcc,
libtool, make, patch, pkg-config
but I think it actually needed make and gcc. Error output said (on my machine, among other):
"You have to install development tools first."
So it was an obvious decision and it helped.
You have to Install some dependencies
sudo apt-get install libmysql-ruby libmysqlclient-dev
I can see most of the people have found the solution to this problem, this is mostly coused but not limited to missing packages, this happened to me after I have purged mysql and reinstalled it. I had to run this command in order to fix my problem:
sudo apt-get install libmysqlclient-dev
This command helped me fix my problem
I was running into this error on my mac and found that I needed to upgrade from mysql 32bit to mysql 64 bit to get this error to go away. I was running OSX 10.6 on an intel macbook pro with ruby 1.9.2 and rails3.0.0
I also needed to install xcode in order to get unix utilities like "make" that are required to compile the gem.
once this was done I was able to run gem install mysql and gem install mysql2 without error.
I got the gem built on Mac OS X 10.6.6 by
1) Ensuring the Developer tools package is installed
2) Downloading the current MySQL package (5.5.8 in my case) from Source
3) Installing the cmake tool from cmake.org
4) Following the instructions in section 2.11 of INSTALL-SOURCE from the mysql distribution files
5) sudo gem install mysql2 -- --srcdir=/usr/local/mysql/include
The gem built successfully, but there are two errors in the documentation that rdoc and ri complain about.
But now when I try to require 'mysql2' I get a
LoadError: no such file to load -- mysql2/mysql2
I was hoping the error I would get was that the libmysqlclient.16.dylib couldn't be found because we figured that out in another post (search for install_name_tool).
My $PATH has /usr/local/mysql in it (that's where my source and built files are located), so I'm a little stumped. If anyone has any thoughts, I'll check back after a few hours of sleep.
For windows user:
You set the lib and include path of your mysql, for instance, if youre using xampp you can have like this:
gem install mysql2 -- '--with-mysql-lib="C:\xampp\mysql\lib" --withmysql-include="C:\xampp\mysql\include"'
Solution only works on Mac OS X
If you've installed MySQL with homebrew, what worked for me was uninstalling MySQL, and installing MySQL Community Edition via the MySQL website (https://www.mysql.com/).
After installed, just re-enter the command to gem install mysql2 or if necessary, sudo gem install mysql2, if you are getting permission denied problems.
If still getting error then follow the steps of mysql2 gem installation on Rails 3 on -
http://rorguide.blogspot.com/2011/03/installing-mysql2-gem-on-ruby-192-and.html
where most of the user were able to install mysql2 gem.
After you get the mysql-dev issues corrected, you may need to remove the bad mysql2 install. Look carefully at the messages after $ bundle install. You may need to
rm -rf vendor/cache/
rm -rf ./Zentest
This will clear out the bad mysql2 installation so that a final $ bundle install can create a good one.
download the right version of mysqllib.dll then copy it to ruby bin really works for me. Follow this link plases mysql2 gem compiled for wrong mysql client library
Got the "You have to install development tools first." error when trying to install the mysql2 gem after upgrading to Mac OS X Mountain Lion. Apparently doing this upgrade removes the command line compilers.
To fix:
I uninstalled my very old version of Xcode (ran the uninstall script in /Developer/Library). Then deleted the /Developer directory.
Went to the AppStore and downloaded Xcode.
Launched Xcode and went into the Preferences -> Downloads, and installed the command line tools.
You are getting this problem because you have not install MySql. Before install mysql2 gem. Install MySQL. After that mysql2 gem will install.
I just wanted to add this answer specifically for Mac Users.
My server was running perfectly fine until I updated my xcode. The while starting my rails server the error was shown like this
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/user/.rvm/rubies/ruby-1.9.3-p448/bin/ruby extconf.rb --with-mysql-
checking for rb_thread_blocking_region()... /Users/user/.rvm/rubies/ruby-1.9.3-
p448/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an
executable file. (RuntimeError)
And there was suggestion to install mysql2 gem at the end of the error message. So when i tried installing it I got the error as above mentioned in this question. The error I got is as follows
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
So as suggested in this post I tried 'brew install mysql' and that quitted saying that mysql version so and so already installed. But there was warning before it saying
Warning: You have not agreed to the Xcode license.
Builds will fail! Agree to the license by opening Xcode.app or running:
xcodebuild -license
Then I tried this sudo xcodebuild -license and type 'agree' at the end. You have to be root to agree to the license.
After this, I again tried bundle install and then everything is working fine as normal. [ Even due to this xcode updation, I had problem with my tower also.]
libmysql-ruby has been phased out and replaced. New command:
sudo apt-get install ruby-mysql libmysqlclient-dev
Under ubuntu 20.04 LTS it's the only solution that have been working for me:
sudo apt-get install ruby-mysql2
According to https://github.com/brianmario/mysql2/issues/1175 , I fixed it by
gem install mysql2 -- \
--with-mysql-lib=/usr/local/Cellar/mysql/8.0.26/lib \
--with-mysql-dir=/usr/local/Cellar/mysql/8.0.26 \
--with-mysql-config=/usr/local/Cellar/mysql/8.0.26/bin/mysql_config \
--with-mysql-include=/usr/local/Cellar/mysql/8.0.26/include