# Yarn

> A tool that adds code packages to JavaScript apps. It is used in place of npm.

**Field:** Software Development  
**Category:** Editors & Tools  
**Also known as:** Yarn Package Manager, yarn add, Yarn Berry

## Think of it like

It is like a second shop on the same street. It sells the same toys, in its own way.

## Definition

Yarn is a free package manager for JavaScript, used in place of npm. It fetches packages from the same npm registry. You add a package with yarn add, and it writes a lockfile called yarn.lock. Yarn came early with ideas like lockfiles and fast offline installs. Teams pick it for speed and for its tools for big projects made of many parts.

## Example

Emma joins a team whose project has a yarn.lock file. She runs yarn install, not npm install, so she gets the same versions.

## Example code

```console
$ yarn add lodash
```

One command adds a package and writes its exact version to yarn.lock.

## Why it matters

Many projects use it. You need to know which tool a project uses, or the installs will not match.

## Common mistake

Mixing Yarn and npm in one project. Each writes its own lockfile, and the two drift apart.

## Three principles

- **Same registry.** It installs the packages npm does.
- **Own lockfile.** It writes yarn.lock, not package-lock.json.
- **One tool per project.** Do not mix it with npm.

## Related terms

- [Package Manager](https://learn.benibix.com/term/development/package-manager)
- [npm](https://learn.benibix.com/term/development/npm)
- [pnpm](https://learn.benibix.com/term/development/pnpm)
- [Lockfile](https://learn.benibix.com/term/development/lockfile)
- [JavaScript](https://learn.benibix.com/term/development/javascript)
- [package.json](https://learn.benibix.com/term/development/package-json)

## Told apart from

- [npm vs Yarn](https://learn.benibix.com/compare/npm-vs-yarn): People think Yarn has its own store of packages, apart from npm, and it does not. Yarn and npm both fetch from the same npm registry. They differ in how they install, and in the lockfile they write. npm writes package-lock.json, and Yarn writes yarn.lock. A project should pick one and stick to it.

## Taught in

- [Yarn, pnpm, Cargo and Homebrew](https://learn.benibix.com/learn/development-tools/yarn-pnpm-cargo-and-homebrew): Coding Tools, 9/13

![A table of four rows. JavaScript: npm, Yarn and pnpm, all fetching from the npm registry. Python: pip and uv, fetching from PyPI. Rust: Cargo, fetching from crates.io. Apps on Mac and Linux: Homebrew, fetching from its own list, called formulae. Each row runs from the language on the left, through its tools, to its registry on the right.](https://learn.benibix.com/diagrams/dev5-package-managers.svg)

---

Source: https://learn.benibix.com/term/development/yarn
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
