【Ruby】Windows で gem install sqlite3 がエラーとなる場合の対処法

2015年10月12日

sqlite3 をインストールするために
以下のような gem コマンドを実行した際に

gem install sqlite3

以下のようなエラーが発生する場合があります。

Temporarily enhancing PATH to include DevKit…
Building native extensions. This could take a while…
ERROR: Error installing sqlite3:
ERROR: Failed to build gem native extension.

D:/Ruby21-x64/bin/ruby.exe extconf.rb
checking for sqlite3.h… no
sqlite3.h is missing. Install SQLite3 from http://www.sqlite.org/ first.
*** 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.

下記の SQLite Download Page で
ソースファイルと DLL ファイルをダウンロードして解凍します。

http://www.sqlite.org/download.html

解凍できたら、
オプション付きで gem コマンドを実行します。

gem install sqlite3 --platform=ruby -- --with-sqlite3-include=G:/sqlite3/source --with-sqlite3-lib=G:/sqlite3/dll

G:/sqlite3/source は sqlite3.h のあるフォルダパスに
G:/sqlite3/dll は sqlite3.dll のあるフォルダパスに変更してください

sqlite3.h と sqlite3.dll は、同じフォルダにあっても大丈夫です。

成功すると以下のようなメッセージが出力されます。

Temporarily enhancing PATH to include DevKit…
Building native extensions with: '–with-sqlite3-include=G:/sqlite3/ –with-sqli
te3-lib=G:/sqlite3/’
This could take a while…
Successfully installed sqlite3-1.3.9
Parsing documentation for sqlite3-1.3.9
Installing ri documentation for sqlite3-1.3.9
Done installing documentation for sqlite3 after 0 seconds
1 gem installed

また Ruby をインストールしたフォルダ内の
lib\ruby\gems\2.1.0\gems\sqlite3-1.3.9\lib\sqlite3 に
sqlite3_native.so が作成されていると思います。

問題解決

Posted by 管理人