1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[windows]An error occurred while installing sqlite3 (1.3.13), and Bundler cannot continue. In Gemfile: sqlite3 解決方法

Posted at

概要

Gemfile に gem 'sqlite3', '1.4.4'を追記し、bundle install したところ、遭遇したエラーです。MacやLinuxでの解決方法はかなりネットに出回っていたのですが、windowsでの解決法はほとんど見なかったので書き留めておきます。

環境
windows10
Rails 6.0.5.1
ruby 3.1.2p20

PS C:\Users\glyce\rails_tutorial_2\hello> bundle install
Fetching gem metadata from https://rubygems.org/...........
Resolving dependencies.......
Using rake 13.0.6
(中略)
Using rails 6.0.4
Installing sqlite3 1.3.13 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
(中略)
An error occurred while installing sqlite3 (1.3.13), and Bundler cannot
continue.

In Gemfile:
  sqlite3

エラー文を読むに、sqlite3のgemをインストールできず、bundlerが続行不可になったようです。

事前準備

sqlite3が使えるか確認。
そもそもインストールや環境変数の設定に失敗している可能性を考えました。

PS C:\Users\glyce\rails_tutorial_2\hello> sqlite3
SQLite version 3.39.1 2022-07-13 19:41:41
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite>

問題なさそうです。

解決方法

sqlite3のパスを指定したコマンドでインストールできました。

gem install sqlite3 --platform=ruby -- --with-sqlite3-include=[path\to\sqlite3.h] --with-sqlite3-lib=[path\to\sqlite3.o]

上のコマンドに、sqlite3.exeが入ったフォルダのパスを当てはめます。私の場合はCドライブ直下だったため、以下のようになりました。

PS C:\Users\glyce\rails_tutorial_2\hello> gem install sqlite3 --platform=ruby -- --with-sqlite3-include=/C/sqlite-tools-win32-x86-3390100 --with-sqlite3-lib=/C/sqlite-tools-win32-x86-3390100
Temporarily enhancing PATH for MSYS/MINGW...
Using msys2 packages: mingw-w64-ucrt-x86_64-sqlite3
Building native extensions with: '--with-sqlite3-include=/C/Users/glyce/soft/sqlite-tools-win32-x86-3390100 --with-sqlite3-lib=/C/Users/glyce/soft/sqlite-tools-win32-x86-3390100'
This could take a while...
Successfully installed sqlite3-1.4.4
Parsing documentation for sqlite3-1.4.4
Done installing documentation for sqlite3 after 0 seconds
1 gem installed

gemのインストールに成功しました! ここでインストールされたsqlite3のバージョンが1.4.4だったため、Gemfileもgem 'sqlite3', '1.4.4'という記述に変更したところ、無事bundle install が完了しました。

参考

大変お世話になりました。ありがとうございます。
https://stackoverflow.com/questions/34171874/an-error-occurred-while-installing-sqlite3-1-3-11-and-bundler-cannot-continue

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?