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 online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
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)