Wednesday, April 11, 2012

How to install sqlite3 ruby gem on RHEL5

I get the following error message when running: rails new myproject

Installing sqlite3 (1.3.5) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

checking for sqlite3.h... yes
checking for sqlite3_libversion_number() in -lsqlite3... yes
checking for rb_proc_arity()... yes
checking for sqlite3_initialize()... no
checking for sqlite3_backup_init()... no
checking for sqlite3_column_database_name()... no
checking for sqlite3_enable_load_extension()... no
checking for sqlite3_load_extension()... no

An error occured while installing sqlite3 (1.3.5), and Bundler cannot continue.
Make sure that `gem install sqlite3 -v '1.3.5'` succeeds before bundling.


Note that the sqlite3 ruby gem is for SQLite version 3.6.16 or newer. The most recent version packaged with RHEL5 is 3.3.6. To check run: rpm -qa sqlite

Solution: Build the latest SQLite from source.
Get the source from here: http://www.sqlite.org/download.html
wget http://www.sqlite.org/sqlite-autoconf-3071100.tar.gz
tar xzvf sqlite-autoconf-3071100.tar.gz
cd sqlite-autoconf-3071100
#Install Development Tools
yum install @development-tools
./configure --prefix=/opt/sqlite3
make
make install

Modify your environment:
edit ~/.bash_profile for current user or globally /etc/profile.d/custom.sh
add /opt/sqlite3/bin to the PATH variable.
verify SQLite3 version: sqlite3 --version should say 3.7.x

Install sqlite3 ruby gem:
gem install sqlite3 -- --with-sqlite3-include=/opt/sqlite3/include/ --with-sqlite3-lib=/opt/sqlite3/lib/