项目bcrypt突发报错cannot load such file --2.3/bcrypt_ext,原正常现失效求解决
Hey there, I’ve run into this exact bcrypt issue before—super annoying when even backups stop working out of nowhere! Let’s break down what’s going on and how to fix it:
What’s Causing This?
The error cannot load such file -- 2.3/bcrypt_ext means bcrypt’s native extension (the compiled part that talks directly to your Ruby environment) is either missing, corrupted, or doesn’t match your current Ruby version. The "2.3" here refers to Ruby 2.3—so if your system switched to a different Ruby version recently (even if you’re using project backups), the old compiled extension won’t work anymore.
Step-by-Step Fixes
First, confirm your Ruby version
Runruby -vin your terminal. If it’s not Ruby 2.3, that’s almost certainly the root problem—bcrypt-ruby 3.0.0 is an older gem that’s tightly tied to specific Ruby versions.Uninstall and reinstall bcrypt-ruby to rebuild the extension
- Uninstall the existing gem completely:
gem uninstall bcrypt-ruby
(If prompted, select all versions to remove every trace) - Reinstall the exact version you need:
gem install bcrypt-ruby -v 3.0.0 - If you’re using Bundler, clean up stale references first:
bundle clean --force bcrypt-rubybundle install
- Uninstall the existing gem completely:
Sync your Ruby version manager (if you use one)
Tools like rbenv or RVM can leave stale gem path references. For rbenv, runrbenv rehashto update your environment. For RVM, tryrvm gemset refreshto sync your gemset with your current Ruby version.Install system dependencies for compiling native extensions
Bcrypt needs basic compilers and headers to build its extension—if these are missing, the gem installs but the critical compiled part fails.- On Mac: Run
xcode-select --installto set up Xcode Command Line Tools. - On Ubuntu/Debian: Run
sudo apt-get install ruby-dev build-essentialto get the required compilers and Ruby headers.
- On Mac: Run
Try upgrading to the newer bcrypt gem (if your project allows it)
Thebcrypt-rubygem was renamed to justbcryptin later versions, which have far better compatibility with modern Ruby releases. If your project doesn’t have strict version locks:- Update your Gemfile to:
gem 'bcrypt', '~> 3.1.18' - Run
bundle install—this will automatically compile a compatible extension for your current Ruby.
- Update your Gemfile to:
Why Even Backups Are Failing
Project backups don’t include compiled native gem files—those are stored in your system’s gem directory or Bundler’s local cache. If your Ruby version changed since the backup was made, the old extension (built for Ruby 2.3) can’t be loaded by your current Ruby environment, hence the error.
内容的提问来源于stack exchange,提问作者SapphireJones

