chrisp
chrisp

Reputation: 2259

How do I install sqlite3 for Ruby on Windows?

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:

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

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

Upvotes: 42

Views: 68070

Answers (9)

Williams
Williams

Reputation: 834

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)".

Upvotes: 81

cmantas
cmantas

Reputation: 1533

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'

Upvotes: 12

vamshi mannem
vamshi mannem

Reputation: 125

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

Upvotes: 1

Lyndon S
Lyndon S

Reputation: 675

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

Upvotes: 1

zawhtut
zawhtut

Reputation: 8561

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

Upvotes: 1

regularmike
regularmike

Reputation: 1167

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

Upvotes: 0

qkdreyer
qkdreyer

Reputation: 21

#!/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

Upvotes: 2

denis-bu
denis-bu

Reputation: 3446

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.

Upvotes: 11

chrisp
chrisp

Reputation: 2259

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.

Upvotes: 0

Related Questions