Setting up Bcrypt for Rails on Windows
You probably end up here because you are looking for a way to install bcrypt in your Windows machine. I needed bcrypt for authentication in my Rails application, I struggled a little bit trying to get it working on rails latest version. You might have a similar error on your console like the one bellow:
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activesupport-4.0.0/lib/active_support/depen dencies.rb:228:in require: 126: The specified module could not be found. – C :/Ruby23-x64/lib/ruby/gems/2.3.0/gems/bcrypt-ruby-3.1.11-x64-mingw32/lib/bcrypt_ext.so (LoadError)
Let’s fix that.
Note: This tutorials is using gems 2.3.0 at the time it was created, which might be different from the current version that you are using. You can simply change ALL “2.3.0” on the commands I used for this tutorial to the version you are currently using.
- Make sure you have the latest version of Ruby installed on your computer. You can download Ruby for Windows from this link: http://rubyinstaller.org/downloads/
- Next is you need to navigate to your rails application then open up your Gemfile and uncomment gem ‘bcrypt’
- Then run bundle install from your terminal to install the bcrypt dependecy.
- If you are currently utilizing bcrypt in your application, when you run using rails server you will get an error similar to the error code bellow:
- C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activesupport-4.0.0/lib/active_support/depen dencies.rb:228:in `require’: 126: The specified module could not be found. – C :/Ruby23-x64/lib/ruby/gems/2.3.0/gems/bcrypt-ruby-3.1.11-x64-mingw32/lib/bcrypt_ext.so (LoadError)
- CD to your gem directory: C:\Ruby23-x64\lib\ruby\gems\2.3.0\gems\bcrypt-3.1.11-x64-mingw32\ext\mri
- Run ruby extconf.rb
- Run make
- Run make install
- This command will generate bcrypt_ext.so
- Copy the generated file “bcrypt_ext.so” to C:\Ruby23-x64\lib\ruby\gems\2.3.0\gems\bcrypt-3.1.11-x64-mingw32\lib\2.3
- If the folder “2.3” (or whatever version you are using) is not present, simply create it then paste the file “bcrypt_ext.so” in it.
- Restart rails, you will see that the bcrypt_ext.so (LoadError) message is gone.
- Congratulations, you just have configured bcrypt in your Windows machine.
If you are experiencing problems with the command: make being unrecognized in your terminal – it means you do not have DevKit installed in your Windows machine. You can follow the tutorial bellow to install DevKit and associate it with your Ruby installation.
- Download DevKit from here: http://rubyinstaller.org/downloads/
- Extract the contents of DevKit, preferably under “C:/RubyDevKit”
- cd C:\RubyDevKit
- ruby dk.rb init
- ruby dk.rb install
- devkitvars.bat
- This command will register all DeKit variables to your Windows environment variables path.
- Try using make command in your CMD, if still not recognized, try adding the DevKit path to your environment variables manually by following the best answer from this link: https://stackoverflow.com/questions/19417715/adding-devkit-to-environmental-path
Do you need help with a project? or have a new project in mind that you need help with?
Contact Me