Thursday, May 9, 2013

Install SQLite3 in Windows 7 for Ruby 2.0 and Rails 4.0

If you are using Rails 4 on Windows 7 (or other windows) you may have problems trying to install the SQLite3 gem. I'm documenting this in case I have to repeat the same steps in other windows and a guide for you.

Before this you need to have installed:
  • Development Kit (DevKit MinGW) from
  • Ruby 2.0.0 (RubyInstaller) from
  • Rubygem
  • gem update --system
    gem update
  • Rails 4
  • gem install rails 
    gem install rails --version 4.0.0.rc1
Everything is installed in a folder inside C:\Development\

To install SQLite3 and the SQLite3 gem:
  1. Create a folder to install SQLite. I use C:\Development\SQLite3
  2. Download sqlite-autoconf-X.tar.gz from to the SQLite3 folder created. Where X is the latest version, as of today it is sqlite-autoconf-3071602.tar.gz
  3. Extract the file and go to the folder where all the files to compile SQLite are
  4. Modify the sqlite.c file to define SQLITE_ENABLE_COLUMN_METADATA
  5. #define SQLITE_CORE 1
    #ifndef SQLITE_PRIVATE
    # define SQLITE_PRIVATE static
    #ifndef SQLITE_API
    # define SQLITE_API
    /************** Begin file sqliteInt.h ***************************************/
  6. Open the bash shell from DevKit MinGW to compile SQLite3
  7. C:\Development\SQLite3\sqlite-autoconf-3071602>bash
    $ ./configure --prefix=/c/Development/SQLite3
    $ make clean
    $ make 
    $ make install
    $ exit
  8. The compilation will create the bin/, include/, lib/ and share/ folders. We'll need them to compile the gem.
  9. gem install sqlite3 -- --with-sqlite3-include=C:\Development\SQLite3\include --with-sqlite3-lib=C:\Development\SQLite3\lib 
  10. Finally - thanks to arBmind - copy the content of the bin/ folder into the ruby bin folder so Ruby will be able to find the libsqlite3-0.dll.
That's it, we are ready to create an application in Windows with SQLite3.


Post a Comment