1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Windows11で「rails s」コマンドを実行したときに出た「cannot load such file -- sqlite3/sqlite3_native」というエラーについて自分なりの解決方法を書いてみた

Last updated at Posted at 2025-09-17

はじめに

タイトルの通り、rails sを実行した際に出たcannot load such file -- sqlite3/sqlite3_nativeというエラーについて自分なりの解決方法を書きました。
色々試した中で成功した例を載せているだけなので参考程度に見ていただけると幸いです。

環境

・Windows11
RubyInstallerの Ruby+Devkit 3.4.5-1 (x64)をインストール
・Rails 8.0.2.1

エラー

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

PS C:/Ruby/Practice> rails s C:/Ruby34-x64/lib/ruby/3.4.0/bundler/runtime.rb:71:in 'block (2 levels) in Bundler::Runtime#require': 
There was an error while trying to load the gem 'sqlite3'.(Bundler::GemRequireError) 
Gem Load Error is: cannot load such file -- sqlite3/sqlite3_native

sqlite3 のネイティブ拡張が正しく読み込めていないようです。

解決方法

筆者と同じ環境で新たにプロジェクトを作成した場合、Gemfileからsqlite3に指定されているバージョンは2.7以上であると思います。

Gemfile
# Use sqlite3 as the database for Active Record
gem "sqlite3", '~> 2.7', '>= 2.7.3'

それを下記のように変更してください。

Gemfile
# Use sqlite3 as the database for Active Record
gem "sqlite3", "= 2.1"

書き換えが完了したら、bundle installしてrails sしてください。
下記の画面が出てきたら成功です。
スクリーンショット (4).png

今回のエラーの原因考察

MSYS2/MinGW環境ではこのような問題が発生することがあるらしく、新しいバージョンのRubyがリリースされても、sqlite3の方がそのバージョンに対応していないときに起こるみたいです。

参考:https://teratail.com/questions/44920

下記エラー文のようにRailsはsqlite3 のバージョンが2.1以上のものを必要としていますが、最初に指定されているバージョン2.7では上手くいきませんでした。

(下記エラーはsqlite3のバージョンを1.6.9にしてbundle installを実行したときに出てきたエラーです。)

Error loading the 'sqlite3' Active Record adapter. 
Missing a gem it depends on?  can't activate sqlite3 (>= 2.1), 
already activated sqlite3-1.6.9.  Make sure all dependencies are added to Gemfile.

また、>=2.1と書いた場合も同じくcannot load such file -- sqlite3/sqlite3_nativeと出たので、=2.1で固定してしまうのが一番互換性が高いのではと思われます。

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?