You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于ROR的后台管理面板登录时出现bcrypt_ext加载失败问题求助

Fixing "Cannot load such file bcrypt_ext" on Windows 10 with Rails 5.1.6 & Ruby 2.3.3

Hey there, I get how frustrating it is when the usual fixes for bcrypt_ext fail—especially when you're trying to get your Devise-based login working. Let's walk through some Windows-specific troubleshooting steps tailored to your setup:

1. Verify Devise & Bcrypt Version Compatibility

First, make sure your Devise version plays nice with both your Rails/Ruby setup and bcrypt. For Rails 5.1.x and Ruby 2.3.x, stick to Devise 4.4.x (newer versions might drop support for older Ruby/Rails). Update your Gemfile:

gem 'devise', '~> 4.4.3'
gem 'bcrypt', '~> 3.1.11' # This version is fully compatible with Ruby 2.3.x

Then run:

bundle update devise bcrypt

2. Ensure Ruby DevKit is Installed & Activated

Windows requires the Ruby DevKit to compile native extensions like bcrypt. If it's missing or misconfigured, you'll hit this error:

  • Locate your DevKit directory (usually C:\DevKit or C:\Ruby23-x64\devkit)
  • Open Command Prompt in that directory and run:
    ruby dk.rb init
    ruby dk.rb install
    

This links the DevKit to your Ruby installation, allowing proper compilation of bcrypt.

3. Clean Gem Cache & Reinstall Bcrypt from Source

Old cached files might be causing conflicts. Let's start fresh:

# Stop all Rails servers and Spring (if running)
spring stop
taskkill /f /im ruby.exe

# Uninstall all bcrypt versions
gem uninstall bcrypt -a

# Clean gem cache
gem cleanup bcrypt

# Install bcrypt with platform-specific flags for Windows
gem install bcrypt -v 3.1.11 --platform=ruby -- --with-cflags="-O2 -Wall"

Then run bundle install to ensure your project uses this fresh installation.

4. Manually Copy the Compiled Extension

Sometimes bundle doesn't properly link the compiled bcrypt_ext.bundle file. Let's fix that:

  1. Find the installed bcrypt gem path:
    gem which bcrypt
    
    This will give you something like C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/bcrypt-3.1.11/lib/bcrypt.rb
  2. Navigate to the lib folder of that gem, copy bcrypt_ext.bundle
  3. Paste it into your project's bundled gem directory:
    your_project/vendor/bundle/ruby/2.3.0/gems/bcrypt-3.1.11/lib/

5. Double-Check Devise Configuration

Looking at your User model and Admin controller code, everything seems correct (you have :database_authenticatable enabled and before_action :authenticate_user! set). Just to be safe, run:

rails generate devise:install

This ensures all Devise initializers and configurations are properly set up for your Rails version.

After trying these steps, restart your Rails server and test the login again. Chances are one of these Windows-specific fixes will resolve the bcrypt_ext load error.

内容的提问来源于stack exchange,提问作者user9857635

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 07:33:53