42

Being really new to Ruby/Rails, and after attempting to resolve the issue myself this weekend I'm making an attempt to seek advice here.

I have a complete Ruby/Apache/Passenger setup done on FreeBSD, and I'm trying to accomplish the task of using Windows as a Ruby development environment.

So far:

  • Ruby is installed, v2.0.0p0 (2013-02-24) [x64-ming32]
  • Rails is installed, v.3.2.12
  • I have the Ruby dev kit installed and registered.
  • I have the sqlite3 dll/exe copied to the Ruby "bin" folder (which is also in my path using the "Start Command Prompt with Ruby" console.)
  • I can start a rails server successfully, and continuing with the http://guides.rubyonrails.org/getting_started.html tutorial to 3.3.
  • ">rake db:create" tells me:

    Please install the sqlite3 adapter: gem install activerecord-sqlite3-adapter ( sqlite3 is not part of the bundle. Add it to Gemfile.)

which I have no "understanding" of. Trying to install activerecord-sqlite3-adapter gives me a "Could not find a valid gem..."

  • ">gem install sqlite3" returns:

    Building native extensions. This could take a while... ERROR: Error installing sqlite3: ERROR: Failed to build gem native extension.

    D:/Development/Ruby200-x64/bin/ruby.exe extconf.rb checking for sqlite3.h... *** extconf.rb failed ***

Right now I'm stuck at the point where I don't even know what state my Ruby on Windows installation is in. I'm trying to follow the main Rails tutorial and it doesn't specify any of these issues (probably because Ruby on Windows seems to be a natural pain for a lot of people.)

What am I missing?!? I'm just trying to install sqlite3 for Ruby on Windows, seems simple right?

If I do ">rais db" the SQLite shell is presented:

SQLite version 3.7.15.2 2013-01-09 11:53:05

Similar questions with steps that do not resolve my issue: Installing SQLite 3.6 On Windows 7

Community
  • 1
  • 1
chrisp
  • 2,181
  • 4
  • 27
  • 35
  • The 'unanswered question' actually has an accepted answer. Have you tried putting the sqlite.dll in your ruby/bin directory? – PinnyM Mar 18 '13 at 15:44
  • I'm not sure how to quote my original question, but here is the bullet "I have the sqlite3 dll/exe copied to the Ruby "bin" folder (which is also in my path using the "Start Command Prompt with Ruby" console.)" – chrisp Mar 18 '13 at 15:47
  • 2
    You are using an x64 ruby, the .dll is probably 32-bit and can't be used. You can try the x64 build of the .dll mentioned [here](http://stackoverflow.com/questions/4315606/precompiled-sqlite-binaries-for-windows-x64). – PinnyM Mar 18 '13 at 15:54
  • 1
    I don't know what the SO etiquette is for this, but I dropped a version of Ruby to 1.9.x, and ">gem install sqlite3" worked without issue. – chrisp Mar 18 '13 at 16:29
  • Is that version x86 or x64? RE: SO etiquette, you can add your own answer and accept it after 7 days if nothing better pops up ;) – PinnyM Mar 18 '13 at 16:32
  • 1
    I believe I followed your hint and specifically ensured I downloaded the 32bit version of Ruby. While I do understand that I can submit my own answer, the issue is, that it's not "the" answer. Version requirements are not discrete for me at this time, but downgrading seems like a "dirty" solution. – chrisp Mar 18 '13 at 16:47
  • At least I'm onto another seemingly common problem -- json gem won't install. :/ /woeisme – chrisp Mar 18 '13 at 17:12
  • 1
    You don't need to downgrade - you can install 32-bit version of ruby 2.0 or use the 64-bit version of the .dll. RE: json gem, what error are you seeing? – PinnyM Mar 18 '13 at 17:13
  • I think I understand where at least my json error comes from. It looks like it's a conflict between the DevKit version and the Ruby version. I'm going to run through the complete Ruby install again to ensure that I have a clean setup. Thank you very much for your patience PinnyM. – chrisp Mar 18 '13 at 17:25
  • possible duplicate of [Installing SQLite3 on Windows - what's the current easiest route?](http://stackoverflow.com/questions/1152928/installing-sqlite3-on-windows-whats-the-current-easiest-route) – Matthew Simoneau Dec 06 '14 at 16:57

9 Answers9

81

Even though the question has been answered, I want to post my research to help others. I found a lot of information online, but being a Ruby newbie I had a tough time following all. The basic answer comes from the following post https://github.com/luislavena/sqlite3-ruby/issues/82 with instructions by "paulwis" on how to properly install sqlite3 for ruby 2.0.0-p0 and some comments on https://github.com/rails/rails/issues/10150 . So here it is:

  1. Install the Ruby Devkit for your setup (DevKit-mingw64-64-4.7.2-20130224-1432-sfx.exe for me since I use a x64 machine)

  2. Download and extract the autoconf package from Sqlite.org

  3. Run msys.bat (it is inside the ruby devkit root folder)

  4. cd into the path where you downloaded the sqlite source (for example: "cd /c/dev/sqlite3" for path "c:\dev\sqlite3" if you are new to MSYS/MINGW32)

  5. Run "./configure"

  6. Run "make"

  7. Run "make install"

  8. Get the sqlite3 gem again, this time specifying the platform and the path to the newly compiled binaries:

    gem install sqlite3 --platform=ruby -- --with-sqlite3-include=[path\to\sqlite3.h] --with-sqlite3-lib=[path\to\sqlite3.o]
    

    For example:

    gem install sqlite3 --platform=ruby -- --with-sqlite3-include=/c:/dev/sqlite3/ --with-sqlite3-lib=/c:/dev/sqlite3/.libs/
    

    (from the paths given in step 4)

  9. Check the Gemfile.lock of your rails app and make sure that it points to the correct sqlite3 version. Mine was "sqlite3 (1.3.7-x86-mingw32)" and manually changed it to "sqlite3 (1.3.7-x64-mingw32)". Removing the platform also works: "sqlite3 (1.3.7)".

starball
  • 20,030
  • 7
  • 43
  • 238
Williams
  • 834
  • 6
  • 2
  • 1
    Thanks so much for this! Unfortunately step #8 failed for me: C:/Ruby200-x64/bin/ruby.exe extconf.rb --with-sqlite3-include=c:\sqlite-auto conf-3071602\sqlite3.h --with-sqlite3-lib=c:\sqlite-autoconf-3071602\.libs\sqlit e3.o checking for sqlite3.h... *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options. – at. May 13 '13 at 03:49
  • 2
    Finally got it to install, the issue was that I had to run the `gem install` command inside the MINGW32 terminal. Now I get this error when starting the Rails server: c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/sqlite3-1.3.7/lib/sqlite3.rb:6:in `require': cannot load such file -- sqlite3/sqlite3_native (LoadError) – at. May 13 '13 at 10:50
  • everything fine till step 8. headers aren't found. i just decided to use virtualbox (college project). – András Gyömrey May 24 '13 at 20:02
  • 1
    In case someone else has the same problem, I had trouble with step 8 until I realized I was using \ instead of / in the MINGW32 window. Switching to forward slashes made it work. – Pam G Jun 14 '13 at 21:20
  • 6
    For step 8, I ran the command out of the MINGW32 window and changed the command to be: `gem install sqlite3 -- --with-sqlite3-include=/c/sqlite-autoconf-3071700/ --with-sqlite3-lib=/c/sqlite-autoconf-3071700/` (I extracted the source code to C:\sqlite-autoconf-3071700 on my machine) – Paul Jun 29 '13 at 19:52
  • I also put my source code in C:\sqlite-autoconf-3071700 and this is the command that finally worked for me: gem install sqlite3 --platform=ruby -- --with-sqlite3-include=C:/sqlite-autoconf-3071700 --with-sqlite3-lib=C:/sqlite-autoconf-3071700/.libs – ColdCold Jul 01 '13 at 01:30
  • Had the same problem. What I did was to open up the Gemfile.lock and change sqlite from 1.3.7 to 1.3.8 (make sure 1.3.8 installed) and it worked. – user938363 Sep 06 '13 at 17:09
  • Thanks a lot! This helped me a lot. And don't forget to restart your rails server after step #9. – jur Oct 08 '13 at 14:51
  • I have marked this the new answer since it is now valid for current installations. At the time of my question this answer would've still been incorrect. I just jumped a bit too early on the release. – chrisp Dec 13 '13 at 18:06
  • Works also for `do_sqlite3` gem. Just adapt step 8. – sschmeck Feb 15 '14 at 23:23
  • @at. Did you figure out the solution to your problem? I'm running into the same error. – Minutiae Oct 20 '14 at 00:22
  • I was having problem with Step 8 (even with Paul's suggestion above). I had to download sqlite.dll from http://sqlite.org/download.html -> http://sqlite.org/2016/sqlite-dll-win64-x64-3110100.zip and put it in C:\Dev\SQLite3 folder. After that Step 8 worked. – Vijay Vepakomma Mar 12 '16 at 09:57
  • Could you go through and check that this answer is still up-to-date? It's the first Google result for "install sqlite3 for rails", which I imagine is pretty common to Google since people want to install Rails but don't know how to install SQLite – Nic Nov 17 '16 at 00:12
  • sqllite is one of the most problematic gems under windows, it breaks constantly. Use this guide: https://medium.com/ruby-on-rails-web-application-development/how-to-install-rubyonrails-on-windows-7-8-10-complete-tutorial-2017-fc95720ee059 – Laszlo Apr 07 '19 at 23:06
  • 1
    i can't see which is msys.bat, I only see msys.exe bro – TheBAST Feb 05 '22 at 06:40
12

This is an old thread, but still relevant.

For us it was as simple as editing the Gemfile and adding a specific version for sqlite.

gem 'sqlite3', '~> 1.3.13'
cmantas
  • 1,516
  • 14
  • 14
11

I was able to install sqlite3 with ruby2.0.0 on win XP32 with following command:

c:\>gem install sqlite3 --platform=ruby -- --with-sqlite3-dir=C:/distr/sqlite --with-sqlite3-include=C:/distr/sqlite

Folder C:/distr/sqlite contains following files

  • shell.c
  • sqlite3.c
  • sqlite3.h
  • sqlite3ext.h
  • sqlite3.def
  • sqlite3.dll

So, basically I've extract sqlite-amalgamation-3071602.zip and sqlite-dll-win32-x86-3071602.zip to C:/distr/sqlite.

HEADS UP

You still need to put copy of sqlite3.dll and sqlite3.def somewhere to PATH. IMHO it's best to keep sqlite3 binaries in ruby's bin folder.

denis-bu
  • 3,426
  • 1
  • 17
  • 11
  • @Lucky, do you have DevKit installed from here http://rubyinstaller.org/downloads/ ? – denis-bu Oct 25 '14 at 16:32
  • 1
    @denis-bu yes I 've already installed it..since this hasnt worked for me i used RailsFTW(a single package rails installer file which has prebundled ruby,rails,and sqlite for windows) and that worked for me.. – Lucky Oct 26 '14 at 11:59
  • 1
    I had to add --with-sqlite3-lib=C:/distr/sqlite also. – Douglas G. Allen Oct 25 '16 at 17:22
2
#!/usr/bin/env sh

mkdir c:/sqlite3x86
wget -P c:/sqlite3x86 http://packages.openknapsack.org/sqlite/sqlite-3.7.15.2-x86-windows.tar.lzma
cd c:/sqlite3x86
bsdtar --lzma -xf c:/sqlite3x86/sqlite-3.7.15.2-x86-windows.tar.lzma
gem install sqlite3 --platform=ruby -- --with-opt-dir=c:/sqlite3x86
cd c:/
rm -rf c:/sqlite3x86
qkdreyer
  • 21
  • 2
1

For windows, go to C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/sqlite3-1.3.13-x64-mingw32/lib/sqlite3.rb

and make sure

require "sqlite3" instead of native

zawhtut
  • 8,335
  • 5
  • 52
  • 76
  • 1
    Thanks. It helped after a simple `gem install sqlite3` (Ruby 2.5.1, Rails 5.2). It now raises another error (file renaming permission failed). My question is: "is it safe? ie, is there a situation I will need to have sqlite3 native?" I feel like touching a library definition... – Al-un Sep 17 '18 at 20:16
  • Strange though, I uninstalled the sqlite3 gem and reinstall it. Compilation options are no longer necessary for windows 10 ming-gw 64 – zawhtut Sep 18 '18 at 09:17
  • u mean something like this : ? ` # support multiple ruby version (fat binaries under windows) begin RUBY_VERSION =~ /(\d+\.\d+)/ require "sqlite3" # require "sqlite3/#{$1}/sqlite3_native" rescue LoadError require "sqlite3" # require 'sqlite3/sqlite3_native' end` – TheBAST Feb 04 '22 at 09:14
1

Get the fat binary from here

https://ci.appveyor.com/project/MSP-Greg/sqlite3-ruby/build/3/job/hhk6ie8gdo545svr/artifacts

and

gem install c:\path\to\downloaded_gem.gem
Lyndon S
  • 645
  • 7
  • 6
1

You should follow this procedure:

  1. gem install bundler (add in Gem file_)
  2. gem 'sqlite3', ' < 1.4'(add in Gem file_)

then run:

install bundler
Gonzalo Garcia
  • 6,192
  • 2
  • 29
  • 32
vamshi mannem
  • 125
  • 1
  • 2
0

I figured I'd put in an answer -- from the comments, for posterity's sake. The issue seemed to be that I grabbed a new version of Ruby/Rails (for Windows) that was not compatible "yet" with SQLite3.

I downgraded to 1.9.x and was able to things running.

chrisp
  • 2,181
  • 4
  • 27
  • 35
  • I'm using Ruby 2.0.0 and it is compatible with sqlite3 – jonathanrz Jun 15 '13 at 22:24
  • @jonathanrz thanks, I'm struggling to get 2.0.0 to compile sqilte3 and am glad to hear that yours is working. Would you mind weighing in on which instructions you followed to get it to compile? – Tyler Gannon Jun 18 '13 at 23:16
  • 1
    @TylerGannon I followed the paths from williams answer, but at step 8 I used denis-bu answer and added the libs dir with the .libs directory inside sqlite3 directory. – jonathanrz Jun 20 '13 at 01:50
  • 1
    After much headache and frustration, @jonathanrz speaks the truth. Follow williams answer, then copy over path/to/sqlite3/.lib up a directory, then run denis-bu's call. Go team! – phyatt Jun 27 '13 at 09:14
  • 2
    @jonathanrz and @phyatt, Thanks for the help. These instructions managed to get the thing to compile with no errors. Now when I try to actually use sqlite3 from ruby I get this error: `126: The specified module could not be found. - c:/Ruby200/lib/ruby/gems/2.0.0/gems/sqlite3-1.3.7/lib/sqlite3/sqlite3_native.so` – Tyler Gannon Jun 29 '13 at 00:46
0

The easiest way to get set up for Ruby on Rails on a Windows machine is by using the RailsInstaller, which automatically installs and configures sqlite3 for you. One step.

http://railsinstaller.org/en

regularmike
  • 1,167
  • 10
  • 22