Error installing mysql2: Failed to build gem native extension

后端 未结 27 2804
清酒与你
清酒与你 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条回答
  • 2020-11-22 09:06

    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.
    0 讨论(0)
  • 2020-11-22 09:07

    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

    0 讨论(0)
  • 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.]

    0 讨论(0)
  • 2020-11-22 09:09

    If you are using yum try:

    sudo yum install mysql-devel
    
    0 讨论(0)
  • 2020-11-22 09:09

    libmysql-ruby has been phased out and replaced. New command:

     sudo apt-get install ruby-mysql libmysqlclient-dev
    
    0 讨论(0)
  • 2020-11-22 09:10

    If you are still having trouble….

    Try installing

       sudo apt-get install ruby1.9.1-dev
    
    0 讨论(0)
提交回复
热议问题