LoadError: cannot load such file Ruby / Rails Origin: Application & API Last updated 5 Nov 2026

Ruby: LoadError: cannot load such file -- nokogiri (or: cannot load such file -- bundler/setup)

require couldn't find the file/gem — it isn't installed, not in the Gemfile, or the load path is wrong.

Exact message you may see LoadError: cannot load such file -- nokogiricannot load such file -- bundler/setupLoadError (cannot load such file -- ./config/boot)cannot load such file -- rails/commandsLoadError: cannot load such file -- sqlite3/sqlite3_native
Seen on: Ruby

Meaning

Run bundle install, add the gem to the Gemfile, use bundle exec, and check ruby -v matches the environment where gems were installed (rbenv/rvm). For local files use require_relative. Missing system libraries cause different (ext build) errors.

Common causes

  • Gem not installed/in Gemfile
  • Not using bundle exec
  • Different Ruby version than the gems were installed for
  • Wrong relative path
  • Case mismatch on Linux

⚡ Quick fix

  1. bundle install then bundle exec ...
  2. Check which ruby && ruby -v and rbenv/rvm
  3. Use require_relative "path" for project files

Detailed fix by platform

Ruby

  1. bundle exec ruby -e 'require "nokogiri"; puts Nokogiri::VERSION'

How to diagnose

  1. Gem — In Gemfile?
  2. Ruby — Same version?
  3. Command — bundle exec?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

ActiveRecord::ConnectionNotEstablished — Rails: ActiveRecord::ConnectionNotEstablished: No connection pool for 'ActiveRecord::Base' found (Ruby / Rails)ActiveRecord::Connect…ArgumentError: missing keyword / unknown keyword — Ruby: ArgumentError: missing keyword: :name / unknown keyword: :nmae (Ruby / Rails)ArgumentError: missin…ArgumentError: wrong number of arguments (given 1, expected 2) — Ruby: ArgumentError: wrong number of arguments (given 1, expected 2..3) (Ruby / Rails)ArgumentError: wrong …Bundler could not find compatible versions for gem — Bundler: Bundler could not find compatible versions for gem "activesupport": In Gemfile: rails (= 7.1.0) depends on activesupport (= 7.1.0) (Ruby / Rails)Bundler could not fin…Bundler: Could not find gem in locally installed gems — Bundler: Could not find gem 'rails (~> 7.1)' in locally installed gems / Could not find rails-7.1.0 in any of the gem sources listed in your Gemfile (Ruby / Rails)Bundler: Could not fi…Failed to build gem native extension — Ruby: ERROR: Failed to build gem native extension. current directory: /gems/pg-1.5.4/ext/pg — An error occurred while installing pg (Ruby / Rails)Failed to build gem n…NameError: uninitialized constant — Ruby: NameError: uninitialized constant UsersController::User (Did you mean? Users) (Ruby / Rails)NameError: uninitiali…Nokogiri: could not find a platform gem / libxml2 build error — Bundler: Your bundle only supports platforms ["x86_64-linux"] but your local platform is arm64-darwin / Could not find gem 'nokogiri (1.16.0-arm64-darwin)' (Ruby / Rails)Nokogiri: could not f…LoadError…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.