Installing Sqlite3 on Windows for Rails 4

Posted by ben on June 04, 2008

The Windows version of Ruby on Rails does not ship with the Sqlite3 database, even though the database.yaml configuration file is preconfigured to use Sqlite.

This is a how to guide on how to install Sqlite3 on your Windows PC. This article assumes that you already have Ruby and Ruby on Rails installed on your PC.

First you will need to download two files from the Sqlite web site http://www.sqlite.org/download.html:

    sqlite-3_5_9.zip (214.32 KiB)
    A command-line program for accessing and modifing SQLite databases. 
    See the documentation for additional information.

    sqlitedll-3_5_9.zip (213.17 KiB)
    This is a DLL of the SQLite library without the TCL bindings. 
    The only external dependency is MSVCRT.DLL.

The first file is the Sqlite command line program used for modifing the Sqlite database. You may or may not use this.

The second file is the Windows DLL library file and Ruby uses this when Rails makes Sqlite database calls.

When both these ZIP files have been extracted you should have the following files:

  • sqlite3.exe
  • sqlite3.def
  • sqlite3.dll

Copy these file to the bin directory of your Ruby installation, if you followed the default Ruby installation it will be located here:

    C:\ruby\bin

Now that you have the Sqlite3 files installed you need to tell Ruby how to use them. To do this you need to download the Ruby bindings for Sqlite3.
Fortunately this is easy to do, using Ruby gems. Simply at the command prompt type the following command:

    gem install sqlite3-ruby

You will now need to tell Gems which version you need as you will be presented with the following output:

    Bulk updating Gem source index for: http://gems.rubyforge.org
    Select which gem to install for your platform (i386-mswin32)
     1. sqlite3-ruby 1.2.2 (mswin32)
     2. sqlite3-ruby 1.2.2 (ruby)
     3. sqlite3-ruby 1.2.1 (mswin32)
     4. sqlite3-ruby 1.2.1 (ruby)
     5. Skip this gem
     6. Cancel installation
    >_

Please select option 1, sqlite3-ruby 1.2.2 (mswin32). All being successful you will get some output like this:

    Successfully installed sqlite3-ruby-1.2.2-mswin32
    Installing ri documentation for sqlite3-ruby-1.2.2-mswin32...
    Installing RDoc documentation for sqlite3-ruby-1.2.2-mswin32...

If you are using Rails 2+ you should be able to run the following rake tasks from your Rails application directory. For example say you created a Rails application located here: C:\MyApp you should be able to execute:

    C:\MyApp>rake db:create
    or
    C:\MyApp>rake db:migrate

Hope this is useful.

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

  1. Soleone Mon, 16 Jun 2008 20:58:53 PDT

    I always installed it conveniently using the modified Gem by _why like this: gem install sqlite3-ruby –source=http://code.whytheluckystiff.net

    See also: http://redhanded.hobix.com/cult/sqlite3Gem_whySSensibilitiesRepack.html

    Just tried it again on a fresh system: Somehow it didn’t work for me this time, but I could swear it worked last time i tried it…

  2. patrick Wed, 20 Aug 2008 15:25:08 PDT

    thx alot! This is an easy and great solution!

  3. Jim Sat, 30 Aug 2008 12:42:41 PDT

    Thank you mate! I was tearing my hair out trying to get this to work on Windows. There is quite a lot of confusion on the internet about this topic, but your solution worked perfectly. Thanks

  4. steve Fri, 02 Jan 2009 10:39:06 PST

    This did not work for me - instead what worked was:

    gem install –version 1.2.3 sqlite3-ruby

    as directed at: http://blog.muse.net.nz/2008/09/07/setup-rails-on-windows-to-use-sqlite3/

    With forementioned cmd I got errors:

    checking for fdatasync() in rt.lib… no checking for sqlite3.h… no

    nmake

    Microsoft (R) Program Maintenance Utility Version 1.50 Copyright (c) Microsoft Corp 1988-94. All rights reserved.

    NMAKE : fatal error U1073: don’t know how to make ‘ruby.h’ Stop.

Comments