LoginSignup
4
4

More than 3 years have passed since last update.

「rails s」で「sqlite3/sqlite3_native」が出た時の対処法

Last updated at Posted at 2019-09-22

開発環境

windows10
ruby 2.5
rails 6.0

エラー内容

rails new の後、サーバを立ち上げたらエラー発生。

$ rails new hello_app
$ bundle install
$ rails s

>>`require': cannot load such file -- sqlite3/sqlite3_native (LoadError)

解決策

・sqlite3.dllをPathがとおったディレクトリに配置
・sqlite3_native.soファイルを生成
・sqlite3_native.soファイルを配置

対処法

こちらから以下のファイルをダウンロードする。

2019-09-22 (2)_LI.jpg
2019-09-22 (3)_LI.jpg

それぞれ解凍します。

sqlite3.hが格納されているファイルをCドライブの直下に置きます。
sqlite3.dllをコピーして、Rubyのbinディレクトリ配下に配置します。
自分の場合は、C:\Ruby25-x64\bin でした。
そして以下のコマンドを実行します。

$ gem install sqlite3 --platform=ruby -- --with-sqlite3-include=C:\sqlite-amalgamation-3290000\sqlite-amalgamation-3290000 --with-sqlite3-lib=C:/Ruby25-x64/bin


>>Temporarily enhancing PATH for MSYS/MINGW...
  Installing required msys2 packages: mingw-w64-x86_64-sqlite3
・・(省略)
This could take a while...
  Successfully installed sqlite3-1.4.1
  Parsing documentation for sqlite3-1.4.1
  Installing ri documentation for sqlite3-1.4.1
  Done installing documentation for sqlite3 after 1 seconds
  1 gem installed

この際、--with-sqlite3-includeにはsqlite3.hを格納した絶対パスを指定し、--with-sqlite3-libにはsqlite3.dllを格納した絶対パスを指定します。
そしたら、sqlite3がインストールされると思います。
さらにこの時に、C:\Ruby25-x64\lib\ruby\gems\2.5.0\gems\sqlite3-1.3.13\lib\sqlite3\sqlite3_native.soが生成されます。

2019-09-22 (4).png
sqlite3_native.soをコピーして、C:\Ruby25-x64\lib\ruby\gems\2.5.0\gems\sqlite3-1.3.13-x64-mingw32\lib\sqlite3を開いてください。
2.4まであると思うので2.5を作り先ほどのsqlite3_native.soを置いてください。
2019-09-22 (5).png
これで、rails sで上手くいくと思います。

追記

別のエラーに対しても上記の対応で解決できました。

rails sを実行した際に、以下のエラーが発生。

Could not find sqlite3-1.4.1 in any of the sources
Run `bundle install` to install missing gems.

gem installを実行した際に以下のエラーが発生。

Gem files will remain installed in C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sqlite3-1.4.2 for inspection.
Results logged to C:/Ruby26-x64/lib/ruby/gems/2.6.0/extensions/x64-mingw32/2.6.0/sqlite3-1.4.2/gem_make.out

参考

【Railsアプリ構築】rails new コマンド実行時、SQLite3のビルドに失敗する
Windows10で「rails server」コマンドを実行したときに「cannot load such file -- sqlite3/sqlite3_native」とエラーが出ることへの対処
間違いがありましたら、編集リクエストをお願い致します。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4