sqlite3 gem, Ruby on Rails and the Windows command line
Solved Email & Outlook
RK
Rachel Kim
August 9, 2016
2 replies
5,860 views
Reviewed by moderators

New to Rails on Windows and bundle install dies building the sqlite3 gem with native extension errors pages long, mentioning missing headers and failed compilation in cmd.

What is the actual working setup for sqlite3 with Rails on Windows?

Accepted Answer
Verified by Kerry Morris, Forum Moderator ยท Reviewed August 2016

The wall you hit is the native extension: the sqlite3 gem compiles C code against SQLite's headers during install, and a Windows machine without the build toolchain and those headers produces exactly your pages of errors. The working setup in order:

1
Install Ruby through RubyInstaller with the Devkit variant, the installer bundle whose name ends in devkit ships the MSYS2 compiler toolchain Rails native gems need. Already installed without it, run ridk install from cmd and choose the full toolchain option, the same result retrofitted.
2
Let the toolchain meet SQLite: with a Devkit Ruby, gem install sqlite3 generally succeeds outright on modern versions because the gem fetches and builds its own SQLite copy. When it still demands an external SQLite, install the development package through the bundled package manager, ridk exec pacman -S mingw-w64-x86_64-sqlite3 in cmd, then retry the gem install.
3
The manual flags route for stubborn combinations of old gems and old guides: download the SQLite source amalgamation and DLL from sqlite.org into a folder like C:\sqlite, then gem install sqlite3 -- --with-sqlite3-include=C:\sqlite --with-sqlite3-lib=C:\sqlite, the double dash passing the header and library locations to the extension build. Ensure sqlite3.dll from that folder sits on the PATH or beside the Ruby executable so runtime finds what compile time used.
4
Verify before blaming Rails: ruby -e "require 'sqlite3'; puts SQLite3::VERSION" in cmd proves the gem loads, then bundle install inside the Rails project completes and rails db:create exercises the whole chain. Failures after a passing require are Rails configuration rather than the native build, a different and smaller problem.

Era honest footnote: Rails on Windows fights this fight repeatedly across gems and the paths of least resistance run through either the Devkit discipline above applied consistently or developing inside a Linux environment on the Windows machine, a VM in this era, where the native gem story is simply quieter. The sqlite3 fix above stands either way, first battle won.

Reinstalled Ruby with the Devkit variant and gem install sqlite3 just worked, the entire drama dissolved by the right installer. The verify one liner then bundle then db:create all green. First Rails page rendering on Windows at last.