$linuxjunkies
>

yarn(1)

Yarn is a fast, reliable, and secure dependency manager for JavaScript packages.

UbuntuDebianFedoraArch

Synopsis

yarn [COMMAND] [OPTIONS]

Description

Yarn is a package manager for JavaScript that works with npm and Node.js. It installs dependencies from package.json, manages versions, and provides a faster, more reliable alternative to npm with offline support and deterministic installs using yarn.lock.

Yarn uses a lockfile to ensure consistent installations across machines and developers. It features workspaces for monorepo support, parallel installation, and excellent error reporting with actionable messages.

Common options

FlagWhat it does
installInstall all dependencies listed in package.json (default when no command given)
add [PACKAGE]Add a new package as a dependency; use --dev for devDependencies
remove [PACKAGE]Remove a package from dependencies
--dev / -DSave as a development dependency instead of production
--global / -gInstall packages globally (available system-wide)
--frozen-lockfileDo not update yarn.lock; fail if it differs from package.json
--offlineUse cached packages only; do not contact npm registry
upgrade [PACKAGE]Upgrade a package to its latest version within constraints
why [PACKAGE]Show which packages depend on the given package
--verbosePrint more detailed output for debugging

Examples

Install all dependencies from package.json and update yarn.lock

yarn install

Add lodash as a production dependency

yarn add lodash

Add jest as a development dependency

yarn add --dev jest

Remove express package and update package.json

yarn remove express

Upgrade react to the latest available version

yarn upgrade react@latest

Install dependencies without modifying yarn.lock (useful in CI/CD)

yarn install --frozen-lockfile

Install create-react-app globally for use anywhere

yarn global add create-react-app

Show which packages in the project depend on webpack

yarn why webpack

Related commands