Installing Sqlite3 on Windows for Rails 48

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 UTC

    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 UTC

    thx alot! This is an easy and great solution!

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

    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 UTC

    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.

  5. SPC Sun, 04 Jan 2009 06:11:02 UTC

    Just a Thank You for your unusually lucid instructions. They worked perfectly for me except that choice #1 on the menu isn’t the right one any more. For other newbs, however, this is no problem: just choose the item marked (mswin32).

  6. SPC Sun, 04 Jan 2009 06:13:32 UTC

    Just a Thank You for your unusually lucid instructions. They worked perfectly for me except that choice #1 on the menu isn’t the right one any more. For other newbs, however, this is no problem: just choose the latest version that is marked (mswin32).

  7. Neil Thu, 08 Jan 2009 21:50:21 UTC

    Same as Steve, and can’t find a fix online–this thread is the top hit for a search for the “checking for sqlite3.h… no” message. Anyone know what’s up?

  8. Neil Thu, 08 Jan 2009 22:07:57 UTC

    Figured it out. This guy has it right:

    http://samdelacruz.blogspot.com/2008/11/install-sqlite3-ruby-for-rails-on.html

    The sqlite3 gem has to be installed with a –version argument. I used 1.2.3 as indicated in the above document, but others may want another version.

  9. Kirk H. Mon, 19 Jan 2009 11:58:58 UTC

    sqlite3-ruby version 1.2.4 is buggy and you can’t install it from a windows prompt. You need to type: “gem install sqlite3-ruby –version=1.2.3″. The most recent version that “works” with windows is 1.2.3. If you do “gem install sqlite3-ruby” you will get errors in windows.

  10. James Carr Mon, 19 Jan 2009 16:24:20 UTC

    I was pulling my hair out as none of the aformentioned gem installations worked… it seems you need two dashes for the version. Thats what worked for me at least.

    gem install sqlite3-ruby –version=1.2.3

  11. Chris Fri, 23 Jan 2009 19:21:15 UTC

    This helped greatly; you’d think the RoR guys would have caught this? Was quite confusing to have to figure out why sqlite3 gems wouldn’t install and furthermore, why would the sqlite3 libraries not be included?

    Oh well.

  12. Johan Mon, 09 Feb 2009 14:46:54 UTC

    Thanks a lot!!!!!

  13. Justin Wed, 11 Feb 2009 13:24:47 UTC

    none of these commands works for me!

    ERROR: while executing gem … Illformed requirement ["ersion=1.2.3"]

  14. RichardW Mon, 16 Feb 2009 06:49:27 UTC

    I’ve got the same error as Justin.

    So i’ve used:

    gem install sqlite3-ruby –version=1.2.3

    And finally it worked for me.

    Grtz, Richard

  15. RichardW Mon, 16 Feb 2009 06:52:42 UTC

    Aha, i see the problem. In the texteditor of this blog converts two dashes automatically into one dash. let try it again:

    gem install sqlite3-ruby – -version=1.2.3 ^ type two dashes before “version”

  16. Brian Fri, 20 Feb 2009 10:27:02 UTC

    Thank you; thank you; thank you!

    It’s too bad there aren’t many more helpful win/ruby developers out there. This has been the most helpful post I’ve found on this topic.

    You’ve saved my forehead from a great amount of further pounding.

  17. Lilla Thu, 26 Feb 2009 05:45:33 UTC

    Thanks a lot. You safed my day.

  18. Egor Tue, 03 Mar 2009 09:36:18 UTC

    Join all the thanks above! It was pretty hard to find, though…

  19. Bruce Blaylock Sun, 08 Mar 2009 20:22:52 UTC

    Once again this is direct proof that Google is your best friend when it comes to finding answers on the web. I would never have figured this out without the help on this page. thanks!

  20. sixto Tue, 10 Mar 2009 20:07:25 UTC

    I tried I downloaded and unzipped the sqlite3 files to my

    c:\windows\system32 (directory — 3 files) and then I tried gem install -v 1.2.3 sqlite3-ruby

  21. Rick Tue, 31 Mar 2009 07:25:17 UTC

    Excellent way to discourage windows users who WANT to learn ruby on rails… hopefully others can find this information easier than I did.

  22. sampath Thu, 02 Apr 2009 19:55:08 UTC

    thanks a lot…!!!

  23. Dirk Taylor Tue, 14 Apr 2009 12:03:57 UTC

    WOW! Finally, eh? I’ve been developing on my production box since my machine crashed christmas day, and couldn’t get this to work! Note, if anyone STILL couldn’t get it to work: If you copied one of the above lines and pasted into your Window, you might have seen a funny u character before version. That’s from copying htmp, somehow. Just backspace & delete BOTH the dashes, then retype them. (Or just copy the whole thing…). What a relief to NOT see the error messages LOL! Thanks again, everyone! Dirk PS. I used version=1.2.3

  24. Kirk H Mon, 27 Apr 2009 13:40:20 UTC

    Yeah guys this bug has been there for about 9 months and every time I load ruby on a WIN32 machine, I always forget that I you need to install ‘gem install sqlite3-ruby –version=1.2.3′. Don’t forget the two dashes before version…

    Also if you’re on windows… make sure you download microsoft visual studio C++ Express edition so that you can compile any gems that require you to compile from source. Otherwise you’ll get those nasty can’t compile native extensions errors!

    That covers about 80% of the headache of developing on windows…

  25. Kurtlar Vadisi Pusu Fri, 22 May 2009 12:43:46 UTC

    Thanks..very very good..

  26. sunil Sun, 07 Jun 2009 00:26:55 UTC

    Thanks a lot for this post!

  27. ajay Thu, 16 Jul 2009 13:06:16 UTC

    Thank you ! this worked for me.

  28. Michael Fri, 14 Aug 2009 11:58:30 UTC

    Worked Perfectly! Very well done and easy to follow. Thanks to you I can move on in my newbie ruby learning. :-)

  29. Alicja Thu, 20 Aug 2009 04:29:20 UTC

    Thank U RichardW! I couldn’t find any good solutions!

  30. luis Sat, 07 Nov 2009 13:20:43 UTC

    thank you!!!!!

  31. Akram Wed, 02 Dec 2009 12:00:18 UTC

    Thank you so much!

    I am using Windows vista with Rails 2.4.5 ruby 1.9.1 p234 and sqlite 3.6.20 and sqlite3-ruby version 1.2.5. The shipped gem version of sqlite3 (3.0.x) does not work very well with webRick.

  32. Getting Ruby to work on Vista64 « Mercurial Wed, 16 Dec 2009 22:18:06 UTC

    [...] I followed tips from emson. [...]

  33. Lynn Tue, 29 Dec 2009 10:12:15 UTC

    Thank you so much for the instructions!

  34. Kim24DN Sun, 03 Jan 2010 21:57:24 UTC

    It’s not so simply to buy a pretty good custom essays, preferably if you are busy. I recommend you to define buy an essay and to be void from scruple that your work will be done by writing service

  35. FrustratedCoder Mon, 04 Jan 2010 23:38:25 UTC

    i got the exe,dll and def files and put them in ruby\bin folder. Since i dont have internet on the box i am trying to install this in, i manually got the sqlite3-ruby gem (from gemcutter) and tried installing it. It didnt work so i got the sqlite3-ruby-1.2.3-x86-mswin32 gem file but it still gives me the same error, failed to build native extension.

    C:\>gem install sqlite3-ruby-1.2.3-x86-mingw32.gem Building native extensions. This could take a while… ERROR: Error installing sqlite3-ruby-1.2.3-x86-mingw32.gem: ERROR: Failed to build gem native extension.

    C:/Ruby/bin/ruby.exe extconf.rb checking for fdatasync() in rt.lib… no checking for sqlite3.h… no

    nmake ‘nmake’ is not recognized as an internal or external command, operable program or batch file.

    Gem files will remain installed in C:/Ruby/lib/ruby/gems/1.8/gems/sqlite3-ruby-1 .2.3-x86-mingw32 for inspection. Results logged to C:/Ruby/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.3-x86-mingw32/ ext/sqlite3_api/gem_make.out

    Please help… am a total noob at this…

  36. uberVU - social comments Fri, 15 Jan 2010 13:17:26 UTC

    Social comments and analytics for this post…

    This post was mentioned on Twitter by aniketzamwar: configring SQlite: http://bit.ly/qhgfX...

  37. ruby version - StartTags.com Mon, 25 Jan 2010 10:41:10 UTC

    [...] should get the version number of Ruby on Rails which will be displayed in the command prompt. …emson… Installing Sqlite3 on Windows for RailsThe Windows version of Ruby on Rails does not ship with the Sqlite3 … gem install sqlite3-ruby. [...]

  38. Tom Fri, 05 Feb 2010 05:05:07 UTC

    That helped a lot, thanks :)

  39. suresh Tue, 16 Feb 2010 20:26:59 UTC

    This really helped me lot. Good article.

  40. Steve Sun, 28 Feb 2010 15:27:08 UTC

    Thanks. The instructions were perfect.

  41. [...] http://blog.emson.co.uk/2008/06/installing-sqlite3-on-windows-for-rails/ Posted by admin   @   14 março 2010 0 comments [...]

  42. Brianoh Fri, 02 Apr 2010 21:19:07 UTC

    Thanks

  43. [...] http://blog.emson.co.uk/2008/06/installing-sqlite3-on-windows-for-rails/ Posted by admin   @   8 junho 2010 0 comments [...]

  44. Arasu Fri, 25 Jun 2010 07:38:00 UTC

    Thank You.

  45. AHMED Tue, 06 Jul 2010 08:01:40 UTC

    THANKS

  46. geoff Tue, 06 Jul 2010 23:19:45 UTC

    i love you man! thanks!

  47. Nick Wed, 14 Jul 2010 19:18:40 UTC

    Thanks. That was really simple.

  48. mostwood Fri, 13 Aug 2010 14:18:39 UTC

    Works for me on Win 7 (64 bit). Thanks!

Comments