Read more

Installing old versions of mysql2 on Ubuntu 20.04+

Tobias Kraze
October 08, 2020Software engineer at makandra GmbH

On some of our older projects, we use the mysql2 gem. Unfortunately, versions 0.2.x (required for Rails 2.3) and versions 0.3.x (required for Rails 3.2) can no longer be installed on Ubuntu 20.04. Trying this either leads to errors when compiling the native extension, or a segfaults when using it.

Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

For Rails 4.2, mysql2 version 0.4.10 seems to work okay. If you still have issues, upgrade to 0.5.x, which should be compatible.

To install it, you have to switch the mysql2 gem to our fork Show archive.org snapshot . In your Gemfile, change mysql2 to either

# for Rails 2.3
gem 'mysql2', :git =>'https://github.com/makandra/mysql2', :branch => '0.2.x-lts'

# for Rails 3.x
gem 'mysql2', git: 'https://github.com/makandra/mysql2', branch: '0.3.x-lts'

If you run into issues when compiling, make sure you have libmariadb-dev installed:

sudo apt remove libmysqlclient-dev
sudo apt install libmariadb-dev

If you have installed mysql2 gems before switching to the fork and installed libmariadb-dev, you might need to uninstall and reinstall all mysql2 versions in all your Rubies.

Posted by Tobias Kraze to makandra dev (2020-10-08 11:26)