Written by James BrittTechnically reviewed by Jim Freeze · Reviewed
A Ruby require LoadError means your loading request failed. To find out why, examine the failed feature, the current dependency environment and the call that requested it. Don’t confuse a false return from require with a missing dependency: false normally indicates that the feature was already loaded. These outcomes call for different actions.
Start with the complete exception and backtrace from a fresh process. Record the launch command and Ruby version before changing anything. A console that has accumulated libraries during a long session can conceal a startup failure. This guide concentrates on interpreting require correctly and keeping error handling from hiding the underlying problem.

Separate Ruby require LoadError from false
First, you want to distinguish Ruby require LoadError failures from false returns. There are three states you should know about. When you successfully ask for a new feature, you get true. An already loaded feature returns false when you request it again. A request that cannot load its feature raises LoadError. Other exceptions could also occur if there is code evaluated during loading. So don’t just look at whether the return value is “truthy” to determine if a library is available.
require 'set'
puts require('set').inspect
# false
The first line loads the feature if necessary. Next, the second line asks for it again. Printing the return value with inspect makes false visible. None of this requires deleting the library, installing the gem or forcing another evaluation. The repeated request has encountered Ruby’s standard loaded-feature behavior.
If your app identifies every false result as “dependency missing,” it can report a failure because an earlier part of startup already loaded the dependency. Let the loading call complete and use the library’s documented interface. Handle an exception separately from any capability check your app actually needs. This avoids confusing the result of this particular request with the availability of the feature.
Read the failed feature before rescuing
Your loading call can start in one library, but fail in another. Therefore, the name you entered at the beginning of your program may not be the correct name of the missing feature. Look at the path of the exception and its backtrace. Its path tells you which request failed. Meanwhile, the backtrace shows you where in your code that request was called.
begin
require 'ruby_doc_missing_adapter_48'
rescue StandardError
puts 'ordinary rescue'
rescue LoadError => error
puts error.class
puts error.path
end
# LoadError
# ruby_doc_missing_adapter_48
The absent-feature example demonstrates the LoadError branch without installing a package. The ordinary rescue branch never runs. Keep both the original message and the path when debugging a live system. Native extensions can fail because shared libraries or compatible binaries are unavailable. Showing only a shortened filename would lose useful information.
In addition, if a failure occurs within another library, track down the first applicable frame or library that relates to your app or library instead of assuming that it occurred within the outer library. A library may be installed but contain an broken dependency. Installing the outer library multiple times won’t fix an uninstalled system library, excluded bundle group, or incorrectly named load item inside another library.
Why ordinary rescue misses the error
LoadError sits below ScriptError in Ruby’s exception hierarchy. Since it isn’t a subclass of StandardError (the default class rescued by a generic rescue clause without specifying an exception type), it often escapes detection when an apparently large rescue clause catches most common application errors.
puts LoadError.ancestors.take(3).inspect
# [LoadError, ScriptError, Exception]
Use a narrow rescue only when you intend to recover from a LoadError. Name the specific exception types you’re trying to catch when creating your rescue clauses. And avoid surrounding an entire app with a rescue clause for Exception solely to catch it. Wider classes like Exception include conditions that your app may wish to pass through. Narrow rescues make their intended recoveries apparent to the next person who reads your code.
Required dependencies generally belong in startup checks that report failures clearly. An optional integration might be absent, or it might be installed but broken internally. Treating both cases as “optional feature disabled” can hide a deployment defect. Keep the diagnostic information and specify which missing component your application is willing to tolerate. Do not discard an unexpected nested failure merely because the outer integration is optional.
Check the Ruby require LoadError environment
Next, distinguish a package installed in your development environment from packages available to your running process. Different Ruby installations, container images, and bundles provide different sets of gems. Compare your running process with the environment where installation worked. Run these comparisons using the same user ID and startup environment whenever possible, instead of comparing against an unrelated terminal.
For bundled applications, use the project’s established bundle entry point. The official bundle exec reference describes how Bundler changes environments and limits which gems your application can load. A gem available outside your project can therefore remain inaccessible within it. Before modifying the loading statement, check the declared dependency and relevant groups.
The name used by your package when installed, the name used by your package when invoked as an executable, and the name used by your package when invoking Ruby are not guaranteed to be equivalent. Validate how to invoke your package as specified by your package’s documentation and inspect the version of your package that you installed. Guessing another gem based on a similar name is a weak repair mechanism, particularly when your actual missing feature resides in your project’s source tree.
| Observed result | Meaning to investigate | Next action |
|---|---|---|
| False return | Feature already loaded | Use the documented interface |
| Missing local feature | Path or deployment mismatch | Check the file and intended base |
| Unavailable gem feature | Entry point or environment mismatch | Check package usage and bundle |
| Failure inside a library | Nested dependency problem | Follow the original backtrace |
Choose the right loading responsibility
Using a bare feature name invokes Ruby’s library search paths and Ruby’s active loading infrastructure. A dot-slash path instead resolves from the current process working directory. Using require_relative invokes loading from the calling file’s directory. Use the form appropriate to where ownership of the dependency lies rather than converting all forms of loading to one.
For a helper function residing in a sibling file, confirm that deployment included it and that it contains no spelling or capitalization errors regarding its invocation. For a packaged dependency, ensure that it has proper packaging and dependency resolution. Adding several directories to Ruby’s global search paths may mask an error and select an alternative file. Ensure that diagnostic experiments are localized and removed after they reveal the cause of an issue.
Rails provides additional responsibilities: it autoloads certain application constants based upon its own conventions. The Rails autoloading guide provides reasons why individual application models and controllers do not typically need explicit require statements. Before providing standalone scripting solutions within Rails, determine if you’re loading an external library or referencing an application constant.
Try the return-value exercise
Create a sample startup routine which asks for the same feature twice. Upon completion of the first query, the second query returns false without throwing an exception. Should this routine indicate a missing dependency, reinstall the package, or continue to utilize its interface? Determine your course of action before proceeding further into this explanation. The short repeated-loading example shown previously illustrates the necessary evidence.
Reveal the answer and the exception boundary
Continue using the library’s documented interface. False indicates that this particular request did not newly load the feature because it had already been loaded. It does not indicate a missing dependency. By contrast, the deliberately absent feature raised LoadError and reached the explicit rescue branch. Neither outcome guarantees that every operation offered by the library will succeed.
Verify a Ruby require LoadError repair
After making one targeted change, rerun the original startup command in a new process. Then execute the operation that depends on the library. Successful loading does not prove that configuration, network access or native functionality works. Check those separately so that a subsequent operational error is not confused with another loading problem.
To create a smaller reproduction, adapt a script from the Ruby code examples collection. Retain the relevant loading order and dependency environment while removing unrelated application work. If the smaller script passes, compare what you removed. A reproduction without the failing bundle context may answer a different question from the original application. Keep a note of the command used for each comparison so that another developer can repeat it.
Official Ruby 4.0.0 WASI ran the three executable examples here. Captured output confirms the repeated-load result, explicit exception handling and displayed ancestry. These tests do not verify native gems, a production filesystem, Bundler or a Rails application. Use your actual deployment runtime to check environment-specific fixes.
Takeaway
Resolve a Ruby require LoadError by separating a loading exception from the return value for an already loaded feature. Keep the failed feature and backtrace, examine the active dependency environment, and rescue narrowly only when recovery is intentional. Finally, repeat startup in a fresh process and exercise the functionality that depends on the library.
