LoginSignup
60
45

More than 3 years have passed since last update.

CentOS環境でRails6.0をSQLite3 (>=3.8)で動かす

Last updated at Posted at 2019-09-05

はじめに

Ruby on Rails 6でSQLiteを使う場合、SQLite3.8以上が必要になります。
ただし、現時点(2019/9月)でCentOSで提供されているSQLiteのパッケージは3.7が最新であり、
普通にアプリケーションを作ると以下のようなエラーが発生します。

$ rake db:migrate
rake aborted!
Your version of SQLite (3.7.17) is too old. Active Record supports SQLite >= 3.8.

これを解消するために、ここでは

  • ソースからインストール
  • gemをwith-sqlite3-libでインストール

することで解決を目指します。

SQLiteの最新版をインストール

# 3.29をダウンロード
$ wget https://www.sqlite.org/2019/sqlite-autoconf-3290000.tar.gz

$ tar xzvf sqlite-autoconf-3290000.tar.gz

$ cd sqlite-autoconf-3290000

# もとから入っているsqliteと競合しないように /opt/sqlite/sqlite3 にインストールします
$ ./configure --prefix=/opt/sqlite/sqlite3

$ make

$ sudo make install

# バージョン確認
$ /opt/sqlite/sqlite3/bin/sqlite3 --version
3.29.0 2019-07-10 17:32:03 fc82b73eaac8b36950e527f12c4b5dc1e147e6f4ad2217ae43ad82882a88bfa6

sqlite3のgemを入れ直し

$ gem uninstall sqlite3

# 上記でいれたlibとincludeのパスを指定してinstall
# --with-sqlite3-includeが必要な旨を教えていただいたので追加
$ gem install sqlite3 -- --with-sqlite3-include=/opt/sqlite/sqlite3/include \
   --with-sqlite3-lib=/opt/sqlite/sqlite3/lib

# 成功!
$ rake db:migrate
== 20190905152058 CreateUsers: migrating ======================================
-- create_table(:users)
   -> 0.0013s
== 20190905152058 CreateUsers: migrated (0.0014s) =============================

※ sqlite3のパスは古いまま(/usr/bin/sqlite3)なのでターミナルから使う場合はパスの修正が必要です。

参考

60
45
2

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
60
45