edo1z blog

プログラミングなどに関するブログです

Rails - cannot load such file -- bcrypt_extというエラー

cannot load such file -- bcrypt_extというエラーがでた。

環境

Windows10 $ ruby -v ruby 2.3.3p222 (2016-11-21 revision 56859) [x64-mingw32] $ rails -v Rails 5.0.2

gemfileに下記を追加したらいいとここに書いてあった。

gem 'bcrypt-ruby', '3.1.1.rc1', :require => 'bcrypt'

だめだった。

ここに書いてあった。

C:\> gem install --no-ri --no-rdoc bcrypt
C:\> cd (path to gems root)\bcrypt-3.1.7-x86-mingw32\ext\mri
C:\(path to gems root)\bcrypt-3.1.7-x86-mingw32\ext\mri> ruby extconf.rb
C:\(path to gems root)\bcrypt-3.1.7-x86-mingw32\ext\mri> make
C:\(path to gems root)\bcrypt-3.1.7-x86-mingw32\ext\mri> make install

path to gems rootは、下記で調べられる。

$ gem environment
  - GEM PATHS:
     - D:/Ruby23-x64/lib/ruby/gems/2.3.0
     - C:/Users/hoge/.gem/ruby/2.3.0
$ cd /D/Ruby23-x64/lib/ruby/gems/2.3.0/gems
$ ls bcrypt-
bcrypt-3.1.11-x64-mingw32/ bcrypt-ruby-3.1.1.rc1/
$ cd bcrypt-3.1.11-x64-mingw32/ext/mri/
$ ruby extconf.rb
$ make
bash: make: command not found

makeをwindows10にインストールした

$ make

make: *** bcrypt_ext.o' に必要なターゲット/D/Ruby23-x64/include/ruby-2.3.0/ruby.h' を make するルールがありません. 中止.

なんだこれは。。

ここに下記が書いてあった。 I solve it with uninstall all bcrypt gem versions with gem uninstall bcrypt and select option 3 (if exist) and uninstall all bcrypt-ruby gem versions with gem uninstall bcrypt-ruby and select option 3 (if exist) then install bcrypt using gem install bcrypt --platform=ruby then add this line gem 'bcrypt', platforms: :ruby to Gemfile, that is it :D.

$ gem uninstall bcrypt
$ gem install bcrypt --platform=ruby
$ vim Gemfile
gem 'bcrypt', platforms: :ruby
$ rm Gemfile.lock
$ bundle

ダメだ。なんだこれは。。。

やっぱmakeを成功させてみる。

ここに書いてあった。

make: *** 'ossl_pkey_dh.o' に必要なターゲット '/include/ruby.h' を make するルールがありません. 中止. Makefileにtop_srcdirの定義が記述されていない。 top_dir行の下に追加する。 top_srcdir = /home/wheezy/src/ruby-2.2.2 $ gedit Makefile $ make clean $ make

無理わからん(T_T)

WindowsのRubyは色々大変らしい。こんなこと頻繁にあったらたまったもんじゃないっす。VagrantかDocker使おう。