LoginSignup
28
27

More than 5 years have passed since last update.

WindowsでRailsTutorialするときに気をつけること

Last updated at Posted at 2018-05-15

環境

Windows10
Ruby+Devkit 2.5.1-1 (x64)
Rails 5.2

Cドライブ直下にRubyをインストールしています。

LoadError

WindowsでRailsTutorialを行っていると、下記のようなエラーが出る場合があります。
その場合、Windowsに合わせたsoファイルの作成が必要です。

cannot load such file -- bcrypt_ext (LoadError)
cannot load such file -- sqlite3/sqlite3_native (LoadError)

sqlite3のインストール

こちらから環境に応じたdllとソースファイルをダウロードして展開
ソースファイル
sqlite-amalgamation-3230100.zip

DLL
sqlite-dll-win32-x86-3230100.zip または sqlite-dll-win64-x64-3230100.zip

sqlite3.dllをRubyのbinフォルダにコピー

コマンド実行

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

※ --with-sqlite3-includeにソースフォルダ、--with-sqlite3-libにRubyのbinフォルダを指定してください。

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

sqlite3-1.3.13-x64-mingw32がインストールされている場合、こちらが優先されるためファイルをコピーします

mkdir C:\Ruby25-x64\lib\ruby\gems\2.5.0\gems\sqlite3-1.3.13-x64-mingw32\lib\sqlite3\2.5
copy C:\Ruby25-x64\lib\ruby\gems\2.5.0\gems\sqlite3-1.3.13\lib\sqlite3\sqlite3_native.so C:\Ruby25-x64\lib\ruby\gems\2.5.0\gems\sqlite3-1.3.13-x64-mingw32\lib\sqlite3\2.5

※sqlite3-1.3.13-x64-mingw32をアンインストールしても動きますが、rails newのたびにインストールされるのでコピーを推奨します

bcryptのインストール

コマンド実行

gem install bcrypt --platform=ruby

次のパスにsoファイルが生成されます。
C:\Ruby25-x64\lib\ruby\gems\2.5.0\gems\bcrypt-3.1.11\lib\bcrypt_ext.so

bcrypt-3.1.11-x64-mingw32がインストールされている場合、こちらが優先されるためファイルをコピーします

mkdir C:\Ruby25-x64\lib\ruby\gems\2.5.0\gems\bcrypt-3.1.11-x64-mingw32\lib\2.5
copy C:\Ruby25-x64\lib\ruby\gems\2.5.0\gems\bcrypt-3.1.11\lib\bcrypt_ext.so C:\Ruby25-x64\lib\ruby\gems\2.5.0\gems\bcrypt-3.1.11-x64-mingw32\lib\2.5

※bcrypt-3.1.11-x64-mingw32をアンインストールしても動きますが、rails newのたびにインストールされるのでコピーを推奨します

28
27
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
28
27