yarn

Fast, reliable, and secure dependency management.

Installation

Node.js >=16.10

Corepack is included by default with all Node.js installs, but is currently opt-in. To enable it, run the following command:

corepack enable

Node.js <16.10

Corepack isn't included with Node.js in versions before the 16.10; to address that, run:

npm i -g corepack

Any time you'll want to update Yarn to the latest version, just run:

yarn set version stable

Usage

Starting a new project.

yarn init -y

The following existing package.json:

{
  "name": "name",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "clean:dir": "rm -rf node_modules",
    "clean:cache": "yarn cache clean",
    "clean": "yarn clean:dir && yarn clean:cache",
    "reinstall": "yarn clean && yarn install"
  },
  "keywords": [],
  "author": "",
  "license": "MIT"
}

Commands

Installing all the dependencies

yarn install

Install packages globally on your operating system.

yarn add global [package]

Installs a package and any packages that it depends on.

yarn add [package]
yarn add [package] --dev

Upgrades packages to their latest version based on the specified range.

yarn upgrade
yarn upgrade left-pad
yarn upgrade left-pad@^1.0.0
yarn upgrade left-pad grunt
yarn upgrade @angular

yarn upgrade –pattern will upgrade all packages that match the pattern.

yarn upgrade --pattern gulp
yarn upgrade left-pad --pattern "gulp|grunt"
yarn upgrade --latest --pattern "gulp-(match|newer)"

Removes an unused package from your current package.

yarn remove [package]

Upgrade Dependencies To The Latest Versions Using Yarn.

yarn up [package]

Running this command will clear the global cache.

yarn cache clean

Upgrade all the packages in your package.json to the latest version

yarn add global npm-check-updates
npm-check-updates -u
yarn add --dev yarn-upgrade-all

Command Reference