• Installing MySQL gem for Ruby 1.9.x

    As of this writing, the MYSQL gem cannot be installed by simply doing a GEM INSTALL with ruby 1.9.1. In order to install the gem, follow these easy steps.

    First download the mysql gem from rubyforge, and unzip it:

    sudo wget https://rubyforge.org/frs/download.php/51087/mysql-ruby-2.8.1.tar.gz
     sudo tar -xzvf mysql-ruby-2.8.1.tar.gz
     cd mysql-ruby-2.8.1

    Now, you will need to compile the gem, do the following:

    sudo ruby extconf.rb

    There are a few options you can use with extconf.rb:
    MySQL header file directory. Default is /usr/local/include.

    MySQL library directory. Default is /usr/local/lib.

    Same as –with-mysql-include=dir/include, –with-mysql-lib=dir/lib.

    Get compile-parameter from mysql_config command.

    On Ubuntu Hardy we were able to not specify any options before we compiled it. Compile now:

    sudo make

    If you wish to test your settings, you can run the following:

    sudo ruby ./test.rb -- [hostname [user [passwd [dbname [port [socket [flag]]]]]]]

    Now to install the gem:

    sudo make install

    For more in depth details for setting up mysql gem and gem details, go here:

    ** If you get an error when trying to do this, and it says a library is missing, odds are you need the mysql dev library:

     sudo apt-get install libmysql++-dev


    Leave a reply