Installing ruby-sqlite3 on Red Hat or CentOS Linux

For my development environment, I like to SQLite3 on Red Hat Enterprise Linux (RHEL / CentOS.)  When working with the gem installer for the sqlite-ruby package I kept getting an error on my newest machine.  I searched online and found no answers anywhere while finding many people having this save problem.  I have found a solution.  There is no need to compile Ruby again from source.

The command used was:

gem install sqlite3-ruby

What I found was the following error:

gem install sqlite3-ruby
Building native extensions.  This could take a while…
ERROR:  Error installing sqlite3-ruby:
ERROR: Failed to build gem native extension.

/usr/bin/ruby extconf.rb install sqlite3-ruby
checking for fdatasync() in -lrt… no
checking for sqlite3.h… no

make: *** No rule to make target `ruby.h’, needed by `sqlite3_api_wrap.o’.  Stop.

Gem files will remain installed in /usr/lib64/ruby/gems/1.8/gems/sqlite3-ruby-1.2.4 for inspection.
Results logged to /usr/lib64/ruby/gems/1.8/gems/sqlite3-ruby-1.2.4/ext/sqlite3_api/gem_make.out

There are two main causes of this problem.  The first is that the correct dev packages are not installed.  Be sure that you install the correct packages for Red Hat.  In RHEL 5, which I use, SQLite3 is now simply SQLite.

yum install ruby-devel sqlite sqlite-devel ruby-rdoc

If you are still receiving the error then you most likely do not have a C compiler installed.  The Gem system needs make and the GCC.  So install those as well.  (Obviously you could combine these two steps.)

yum install make gcc

Voila, you SQLite / SQLite3 installation on Red Hat (RHEL), Fedora, or CentOS Linux should be working fine.  Now your “rake db:migrate” should be working.

Update: If you follow these direction and get the error that sqlite3-ruby requires Ruby version > 1.8.5 then you can go to my follow-up directions on
SQLite3-Ruby Gem Version Issues on Red Hat Linux and CentOS

Join the Conversation


  1. Thank you for you guidance. I had the same problem, and I finally solved it now.
    I’m on Ubuntu 8.10 platform. So just in case if someone using a debian (.deb) based machine,
    then write
    sudo apt-get install ruby-dev sqlite3 libsqlite3-dev rdoc

    By the way, I had all packages already installed. But after installing ruby-dev and libsqlite3-dev, the problem disappeared.
    Now sudo gem install sqlite3-ruby should work just fine.
    (I guess ruby-dev isn’t necessary, or it may be, I don’t know).

  2. Thanks Scott!!!
    I was getting an ugly error when trying to install the ruby sqlite gem on a centos box:
    ERROR: Error installing sqlite3-ruby:
    ERROR: Failed to build gem native extension.

    I had sqlite installed via yum, but I was missing sqlite-devel (which your post exposed). Now the gem install for sqlite succeeds:
    sudo gem install sqlite3-ruby


  3. Glad that I could help. Funny enough I was doing a Rails on CentOS installation just yesterday and, of course, had an installation problem. I knew that I had gotten it to work before but had completely forgotten about this post. So I Google’d it quickly and found the answer posted elsewhere with a link back to my own site! So I ended up following my own directions as well 🙂

  4. I am using CentOS 5.3 i386. sqlite is not working. Though I have install sqlite3. but it is not available in php.ini file.

    how to solve this problem?

  5. Please any one help me to install and configure php with sqlite in centos 5.3 i386 with detail step.

  6. You need to specify the versio like that:

    gem install sqlite3-ruby –version ‘= 1.2.4’

Leave a comment