← 返回命令列表

Linux command

yarn 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Install all dependencies

yarn install

Add a package

yarn add [package]

Add a package

yarn add --dev [package]

Remove a package

yarn remove [package]

Upgrade packages

yarn upgrade

Run a script

yarn run [script]

Initialize a new project

yarn init

Interactively upgrade

yarn upgrade-interactive

说明

Yarn is a fast, reliable, and secure dependency manager for JavaScript. It caches every package it downloads, enabling offline installation of previously fetched packages. Yarn parallelizes operations for faster performance compared to npm. Running yarn with no command executes yarn install. Running yarn script executes a user-defined script from package.json. The lockfile yarn.lock ensures consistent installations across machines. Yarn 2+ (Berry) introduces Plug'n'Play for zero-install workflows and improved workspace support. Configuration can be set globally or per-project via .yarnrc.yml.

参数

install
Install all dependencies from package.json.
add _package_
Add a package to project dependencies.
remove _package_
Remove a package from the project.
upgrade _package_
Upgrade packages to their latest version based on version range.
run _script_
Execute a script defined in package.json.
init
Initialize a new project, creating package.json.
publish
Publish a package to a registry.
create _starter-kit_
Create a new project from a starter kit.
config
Manage Yarn configuration settings.
cache clean
Clean the global cache.
--dev, -D
Add package as a dev dependency.
--global, -g
Install package globally.
--verbose
Print verbose output for the command.
--cwd _directory_
Specify a working directory.
--mutex _type_
Ensure only one Yarn instance runs (file or network).
--help
Display help for a command.
--version
Display version information.

FAQ

What is the yarn command used for?

Yarn is a fast, reliable, and secure dependency manager for JavaScript. It caches every package it downloads, enabling offline installation of previously fetched packages. Yarn parallelizes operations for faster performance compared to npm. Running yarn with no command executes yarn install. Running yarn script executes a user-defined script from package.json. The lockfile yarn.lock ensures consistent installations across machines. Yarn 2+ (Berry) introduces Plug'n'Play for zero-install workflows and improved workspace support. Configuration can be set globally or per-project via .yarnrc.yml.

How do I run a basic yarn example?

Run `yarn install` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does install do in yarn?

Install all dependencies from package.json.