Win10下Ruby on Rails中bcrypt无法正常使用的问题求助
Troubleshooting bcrypt Installation &
rake db:migrate Errors on Windows 10 64-bit (Ruby 2.3.3 + Rails 4.2.8) Hey there, I feel your frustration—going through countless fixes without progress is so disheartening. Let's break down this bcrypt issue step by step, tailored to your specific setup:
1. First, Verify DevKit is Properly Configured
Even if you installed DevKit via Rails Installer, it might not be correctly linked to your Ruby installation. Let's fix that first:
- Open a command prompt and navigate to your DevKit directory (usually
C:\RailsInstaller\DevKit) - Run these commands to bind DevKit to your Ruby:
ruby dk.rb init ruby dk.rb install
This ensures your Ruby can access the DevKit's compilation tools when building native gems like bcrypt.
2. Fully Clean Up Old bcrypt Installations
Lingering old versions can cause conflicts. Let's wipe them all:
- Uninstall all bcrypt-related gems:
gem uninstall bcrypt --all gem uninstall bcrypt-ruby --all # Some older setups use this package name - Confirm they're gone by checking your gem list:
gem list bcrypt - Double-check your project's
Gemfileto ensure it specifies the correct version:gem 'bcrypt', '3.1.7'
3. Install bcrypt with the Right Environment
The --platform=ruby flag needs the DevKit environment loaded to work. Here's the correct workflow:
- In the same command prompt where you ran the DevKit setup, load the DevKit environment variables:
cd C:\RailsInstaller\DevKit devkitvars.bat - Navigate back to your Rails project directory, then install bcrypt:
gem install bcrypt -v 3.1.7 --platform=ruby - If manual compilation is needed (in case the above fails):
- Download the bcrypt 3.1.7 source zip from RubyGems, extract it to a folder without spaces
- In the DevKit-enabled command prompt, navigate to that folder and run:
ruby extconf.rb make make install
4. Finalize & Test
- After installation, sync your project's dependencies:
bundle install - Now try running your migration again:
rake db:migrate
Quick Extra Checks
- Ensure your Ruby installation path has no spaces (Rails Installer's default
C:\RailsInstaller\Ruby2.3.3is safe—spaces break compilation paths) - Run
bundle show bcryptto confirm your project is using the 3.1.7 version you just installed
内容的提问来源于stack exchange,提问作者Mihir Deshpande
相关产品推荐
相关产品推荐

