Ruby Install Mysql2 Gem Windows

Ruby Install Mysql2 Gem Windows Average ratng: 9,9/10 6507 reviews

The problem Cutting a long story short, I couldn’t for the life of me get the mysql2 gem to compile and install. This is the error message I got: C:/Ruby200-x64/bin/ruby.exe extconf.rb checking for main in -llibmysql. No.

Ruby Install Mysql2 Gem Windows

Nov 13, 2013. Installing mysql2 (0.3.14). Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. C:/Ruby200/bin/ruby.exe extconf.rb. Checking for ruby/thread.h. Checking for rb_thread_call_without_gvl() in ruby/thread.h. Checking for rb_thread_blocking_region(). Checking for. ERROR: Error installing mysql: ERROR: failed to build gem native extension C:/Ruby200-x64/bin/ruby.exe extconf.rb checking for main() in. Looks like it can be a bit more tricky than just a gem install to get the mysql2 gem running on windows but you shouldn't have to switch OSes just to get it running.

Windows

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. I followed numerous instructions from across the internet as to how this might be achieved. Most seemed to indicate that you could set the -with-mysql-dir flag accordingly and although this got me close, no dice. The solution This is what worked for me.

Ruby install mysql2 gem windows

Hopefully it’ll help someone else.

If you cannot install the MYSQL2 gem in Windows, you need to download the C-Header files from MYSQL. Unlike other gems, MYSQL2 requires direct linking into some of the native build files provided by the library. Unless you have MYSQL installed already, it means you need to download – and reference – this library from the Internet. The problem is that since the MYSQL2 gem requires certain files to help it connect to the Internet, the gem uses these to at build. The error you’ll receive will mention “Failed to build native extensions”. This means your Windows system did not have the header files required for the gem to be installed correctly. The way to resolve this is to first log onto the MYSQL website and look for “C-Connector”.

This is basically the “driver” for MYSQL, allowing Windows to call a number of pre-compiled functions to help it communicate with local or external MYSQL installations. The purpose of this download is to ensure your computer has the necessary files to install the gem.

Once you have found the MYSQL C-Connector file, you need to download it to your hard drive. From this, unzip the file and place its contents on your hard drive. You must put it in a path which has no spaces, otherwise the installation reference will break. A path such as C:/downloads/mysql-c-connector/files will work fine. Please note you do NOT need to install this – only download the zipped archive, we can remove it after the gem has been installed. If you have downloaded and placed the files on your hard drive, you need to then install the gem again.

To do this, you should load up CMD and type the following command “gem install mysql2 –platform=ruby — ‘–with-mysql-dir=”C:mysql-connector-path”‘”. This command will reference the newly installed MYSQL C-Connector library files which Ruby requires to build the gem. If you’ve downloaded / installed it correctly, this should allow Ruby to install the required files etc. If successful, the cmd will explain the gem has been installed; if not, it will likely be that you have either downloaded the incorrect files OR you have not got another necessary library installed on your system. Since Windows comes with no external libraries, it’s necessary to install any required from the Internet. This is one of the reasons most people don’t like developing with Windows – ultimately, if you’re able to download the correct header files, you should be fine.

Posted :