Running into trouble with the sqlite3-ruby
gem and seeing errors about extconf.rb
or mkmf
? Don’t worry—you’re not the only one. This is a pretty common snag, especially for folks working on Ruby projects that use SQLite as their database. The good news? It’s not as scary as it looks. Here’s how to fix it.
Table of Contents
Why You’re Getting the LoadError
This error shows up when the sqlite3-ruby
gem can’t find the libraries or tools it needs to build its native extensions. You’ll see something like this:
checking for sqlite3.h... no
sqlite3.h is missing. Install SQLite3 from your package manager.
*** extconf.rb failed ***
Basically, your system is missing the SQLite3 development files, which include the headers and libraries the gem needs to compile.
Here’s how to get everything working based on your operating system:
Step 1: Is SQLite3 Already Installed?
First, check if SQLite3 is already installed. Run this command:
sqlite3 --version
If it spits out a version number, you’re good on that front. If not, you’ll need to install it.
Step 2: Install SQLite3 and Development Tools
Depending on your OS, the steps to install SQLite3 and its dev tools are different.
For Ubuntu/Debian Users
Run these commands:
sudo apt update
sudo apt install sqlite3 libsqlite3-dev
For Fedora Users
Run this:
sudo dnf install sqlite sqlite-devel
For macOS Users
If you’re on macOS and using Homebrew, do this:
brew install sqlite3
If you still have issues, check that SQLite3’s location is in your PATH. Add it to your shell config file like this:
export PATH="/usr/local/bin:$PATH"
Step 3: Make Sure Ruby and Build Tools Are Updated
Outdated Ruby or missing build tools can also cause problems. Here’s how to get everything up to date:
On Ubuntu/Debian
sudo apt install build-essential
On Fedora
sudo dnf groupinstall "Development Tools"
On macOS
Install Xcode’s command-line tools:
xcode-select --install
Step 4: Install the sqlite3 Gem
Now that your system is ready, install the gem:
gem install sqlite3
If you’re using Rails, add this to your Gemfile
:
gem 'sqlite3', '~> 1.4'
Then run:
bundle install
Common Issues and Fixes
Still stuck? Here are a few extra things to try:
- Reinstall the Gem: Sometimes starting fresh helps:
gem uninstall sqlite3 gem install sqlite3
- Check Your Compiler: If you’re using an older compiler, it might not work with your Ruby version. Update your compiler if needed.
- Set Build Flags: If the gem can’t find the SQLite3 headers, point it in the right direction:
gem install sqlite3 -- --with-sqlite3-include=/path/to/sqlite3/include --with-sqlite3-lib=/path/to/sqlite3/lib
- Use a Compatible Ruby Version: Check the gem’s documentation to make sure your Ruby version is supported.
Wrapping Things Up
Errors with extconf.rb
and mkmf
can feel like a hassle, but they’re totally solvable. Just make sure SQLite3 and its dev libraries are installed, your Ruby setup is updated, and you’ve got the right build tools. Once everything’s in place, installing the sqlite3-ruby
gem should work like a charm.
FAQ
What is extconf.rb
?
It’s a Ruby script that creates a Makefile
to build native extensions. If it fails, it’s usually because required libraries or headers are missing.
Why Do I Need sqlite3.h
?
This header file is needed to compile SQLite3-related code. It’s included in packages like libsqlite3-dev
.
Can I Use a Different Database with Rails?
Definitely. Popular options include PostgreSQL and MySQL. Just update your Gemfile and Rails config to use the appropriate gem.
How Do I Check My SQLite Version?
Run the command: sqlite3 –version
After running the commands you suggest, I am still getting the same error when I try to install the Ruby gem. Any ideas what else I could be missing?
Figured it out! After searching around to uncover why it was failing to load ‘mkmf’, I found that I needed to install the ruby1.8-dev package:
sudo apt-get install ruby1.8-dev
Kudos goes to: http://mentalized.net/journal/2006/01/24/no_such_file_to_load_mkmf/
Thanks, I really appreciate this help. 🙂
Great, after installing ruby1.8-dev, everything installed just as expected! Btw, when installing sqlite3-ruby, i got this sweet little message:
Hello! The sqlite3-ruby gem has changed it’s name to just sqlite3. Rather than
installing `sqlite3-ruby`, you should install `sqlite3`. Please update your
dependencies accordingly.
Thanks from the Ruby sqlite3 team!
<3 <3 <3 <3
maybe you should update your howto, too 😛
Thanks again, suteno
ahah! I run Linux Mint 11 and the command:
sudo apt-get install libsqlite3-dev
is what made the difference, finally I could install the sqlite3 gem
This helped out a lot! Thanks!
That worked! (ruby1.8-dev)
Thanks Matt! I was stuck installing the selenium-webdriver gem, but installing the ruby dev package fixed this error. I thought gems were supposed to figure out dependencies like this?
It worked perfectly!
sudo apt-get install sqlite3
sudo apt-get install libsqlite3-dev
sudo gem install sqlite3-ruby
sudo gem install sqlite3
Thank you very Sood for the suggestion!
Try:
sudo apt-get install ruby-dev
And if your on a Windows Machine?