3

I tried all methods of here. But still, the same error occurs.

An error occurred while installing mysql2 (0.5.2), and Bundler cannot
continue.
Make sure that gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/'
succeeds before bundling.

My spec is:

  • MacOS Mojave 10.14.1

  • Ruby 2.5.3p105

  • Mysql 8.0.12 with Homebrew

Gemfile:

gem "rails"
gem "mysql2", "0.5.2"

Could you kindly tell me a solution?

hernanvicente
  • 914
  • 8
  • 18
kai00
  • 57
  • 1
  • 11
  • 1
    When you run `gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/'`, what is the output? – Sara Fuerst Nov 21 '18 at 15:53
  • I tried to install older versions of Mysql2 0.5.1, 0.5.0, too. But it is failed... – kai00 Nov 21 '18 at 15:54
  • Hi, Sara ERROR: While executing gem ... (Errno::EACCES) Permission denied @ rb_sysopen - /Users/daisuke/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/mysql2-0.5.2/CHANGELOG.md – kai00 Nov 21 '18 at 15:56
  • I did sudo, too. sudo gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/' Password: Building native extensions. This could take a while... ERROR: Error installing mysql2: ERROR: Failed to build gem native extension. – kai00 Nov 21 '18 at 15:58
  • Hi, hernanvicente. macOS Mojave 10.14.1 – kai00 Nov 21 '18 at 16:09
  • Sorry, I did missread your comment above. Could you please share share the result of your trace? Try to run your instruction appending a `--trace` – hernanvicente Nov 21 '18 at 16:13
  • Possible duplicate of [ERROR: Failed to build gem native extension - Error installing mysql2](https://stackoverflow.com/questions/19765290/error-failed-to-build-gem-native-extension-error-installing-mysql2) – Sara Fuerst Nov 21 '18 at 16:13
  • I think that you are probably missing to install some dev package dependency. Try: `brew install mysql-connector-c` and then later `brew install libmysqlclient-dev` – hernanvicente Nov 21 '18 at 16:15
  • brew install libmysqlclient-dev Error: No available formula with the name "libmysqlclient-dev" ==> Searching for a previously deleted formula (in the last month)... Warning: homebrew/core is shallow clone. To get complete history run: git -C "$(brew --repo homebrew/core)" fetch --unshallow Error: No previously deleted formula found. ==> Searching for similarly named formulae... Error: No similarly named formulae found. ==> Searching taps... ==> Searching taps on GitHub... Error: No formulae found in taps. – kai00 Nov 21 '18 at 16:26
  • @Daisuke can you try to install your mysql gem providing the actual mysql directory. Check https://coderwall.com/p/whbzrw/install-mysql2-gem-in-mac-os-x-with-mysql-installed-via-brew – hernanvicente Nov 21 '18 at 16:46
  • @hernanvicente I did it. however... sudo gem install mysql2 -- --with-mysql-dir=/usr/local/bin/mysql Building native extensions with: '--with-mysql-dir=/usr/local/bin/mysql' This could take a while... ERROR: Error installing mysql2: ERROR: Failed to build gem native extension. – kai00 Nov 21 '18 at 23:56

3 Answers3

0

This is a very good post. I was facing the same issue using mac. What I ended up doing was the following.

  1. I changed the permission for the Gemfile. I used chmod 755 Gemfile.

  2. I used sudo bundle install. This allowed me to install all the gems in the Gemfile.

  3. I did a rake db:create and rails server.

Got things working. Hope it fixes your issue too.

A1aks
  • 187
  • 1
  • 2
  • 15
0

I had the same issue, when setting up a new machine.

Just running

brew install mysql

fixed the failing mysql gem installation for me.

0

Don't know if this will help, but I had imilar problems on Mac with MySQL twice. First time I just did a complete reinstall, I made sure there were no MySQL files left in the system. I think I followed this guide. The second time I read that it's an issue with symoblic links which I managed to fix with brew prune (I see that it might have been renamed to brew cleanup now - worth to check both).

sloneorzeszki
  • 1,274
  • 3
  • 12
  • 22