Error installing mysql2: Failed to build gem native extension

后端 未结 27 2814
清酒与你
清酒与你 2020-11-22 08:06

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 mysq

27条回答
  •  -上瘾入骨i
    2020-11-22 09:08

    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.]

提交回复
热议问题