LoginSignup
13
15

More than 5 years have passed since last update.

Windows10で「rails server」コマンドを実行したときに「cannot load such file -- sqlite3/sqlite3_native」とエラーが出ることへの対処

Last updated at Posted at 2018-12-15

はじめに

タイトルのとおりのエラーが出ることへの対処法。
対処法はこちらの@jun_mokaさんの記事のとおりです。ありがとうございました m(_ _)m
ですので、これは自分用のメモです。

環境

  • Windows10
  • RubyInstallerのRuby+Devkit 2.5.3-1 (x64)をインストール
  • ruby 2.5.3p105 (2018-10-18 revision 65156) [x64-mingw32]
  • Rails 5.2.2

エラー

Railsをインストールしてrails new hogeでプロジェクトhogeを作成しました。
hogeディレクトリに移動し、rails serverコマンドでRailsアプリを実行したところ、以下のエラーメッセージが出力され、実行できませんでした。

Traceback (most recent call last):
        43: from bin/rails:4:in `<main>'
        42: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
        41: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
        40: from C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'

<<中略>>


C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require': cannot load such file -- sqlite3/sqlite3_native (LoadError)

sqlite3のロードに失敗したような感じです。

解決手順

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

1. sqlite3.dllをPathがとおったディレクトリに配置

SQLite Download Page
から「sqlite-dll-win64-x64-3260000.zip」をダウンロードします。
自分のWindowsは64bitなので64bitを選びました。

kjfsalsfdasdf.png

これを解凍すると「sqlite3.dll」が入っているので、これをPathがとおったディレクトリにコピーします。
Pathさえとおっていればどこでもいいのですが、今回はRubyのインストールディレクトリ内の「bin」ディレクトリに置きました。
C:\Ruby25-x64\bin

2. sqlite3_native.soファイルを生成

先程と同じSQLite Download Pageから、「sqlite-amalgamation-3260000.zip」をダウンロードします。

adfadfasdfa.png

これを解凍します。

次に以下のコマンドを実行してsqlite3_native.soファイルを生成します。

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

これでC:\Ruby25-x64\lib\ruby\gems\2.5.0\gems\sqlite3-1.3.13\lib\sqlite3\sqlite3_native.soにファイルが生成されます。

3. sqlite3_native.soファイルを配置

RubyInstallerで64bitを選んでいる場合は、C:\Ruby25-x64\lib\ruby\gems\2.5.0\gems\sqlite3-1.3.13-x64-mingw32ディレクトリがあると思います。sqliteのバージョンは違うかもしれませんが。

そこからさらに進んでいくとC:\Ruby25-x64\lib\ruby\gems\2.5.0\gems\sqlite3-1.3.13-x64-mingw32\lib\sqlite3に名前が数字のディレクトリがいくつか入っていると思います。

image.png

2.4まであります。
ここに2.5ディレクトリを新規作成し、その中に先程のsqlite3_native.soをコピーします。

以上です。

確認

もう一度rails serverコマンドを実行します。
すると今度は以下のように表示され、Railsアプリの起動に成功しました。

=> Booting Puma
=> Rails 5.2.2 application starting in development
=> Run `rails server -h` for more startup options
*** SIGUSR2 not implemented, signal based restart unavailable!
*** SIGUSR1 not implemented, signal based restart unavailable!
*** SIGHUP not implemented, signal based logs reopening unavailable!
Puma starting in single mode...
* Version 3.12.0 (ruby 2.5.3-p105), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop

ブラウザでlocalhost:3000にアクセスして、以下のページが表示されたら成功です。

image.png

Yes! I'm on Rails!

13
15
1

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
13
15