LoadError
RubyFATALCommonLoad
File or gem could not be loaded
Quick Answer
Run bundle install and verify the gem name in the require statement matches the installed gem.
What this means
Raised by require or load when the specified file cannot be found or loaded. Most commonly caused by a missing gem, a wrong require path, or a gem that is not in the Gemfile.
Why it happens
- 1Gem not listed in Gemfile or not installed
- 2Incorrect require path (e.g., require "active_record" instead of require "activerecord")
- 3File does not exist at the specified relative or absolute path
Fix
Install missing gem and require correctly
Install missing gem and require correctly
# Gemfile
gem 'nokogiri'
# Terminal
# bundle install
# Code
require 'nokogiri'
doc = Nokogiri::HTML('<h1>Hello</h1>')Why this works
bundle install adds the gem to the load path so require can find it.
Code examples
Reproducing the errorruby
require 'nonexistent_gem' # LoadError: cannot load such file -- nonexistent_gem
Conditional requireruby
begin require 'oj' rescue LoadError require 'json' # fallback to stdlib end
Require relative fileruby
require_relative '../lib/my_module' # uses path relative to current file, not load path
Same error in other languages
Sources
Official documentation ↗
Ruby Core Documentation
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev