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

**Code:** `LoadError: cannot load such file` · **Category:** Ruby / Rails · **Seen on:** Ruby

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

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/ruby/loaderror-cannot-load-such-file)
