title: Yarn download and installation, common configuration and command summary
date: 2023-01-13 14:47:32
tags:
- Development tools and environment
categories: - Development tools and environment
cover: https://cover.png
feature: false
1. Node.js
It is recommended to install Node.js first, see another article: Node.js multi-version installation and NPM mirror configuration_fan223's blog
2. Download and install
Since Node.js comes with a package manager NPM, the easier way to install Yarn is npm install --location=global yarn
to
If you want to upgrade the Yarn version, you can first check the latest version number of Yarn from the Internet. Generally, the console will automatically prompt when there is a new version of Yarn, and then use the command to specify the version number to upgrade.npm install [email protected] --location=global
3. Modify the installation location of Yarn global package and cache
- Check the current Yarn bin location:
yarn global bin
- Check the current Yarn global installation location:
yarn global dir
- Check the current Yarn global cache location:
yarn cache dir
- Modify the current global installation location of Yarn:
yarn config set global-folder "自定义路径"
, if the global directory installed with Yarn does not take effect after modification, reopen cmd and install with Yarn - Modify Yarn's cache accordingly:
yarn config set cache-folder "自定义路径"
- Clear the global cache:
yarn cache clean
4. Basic commands
NPM | Yarn |
---|---|
npm install | yarn |
npm install xxx --save | yarn add xxx |
npm uninstall xxx --save | yarn remove xxx |
npm install xxx --save-dev | yarn add xxx --dev |
npm update --save | yarn upgrade |
- Installation package:
yarn [global] add [package]@[version]
- Update package:
yarn upgrade [package | package@tag | package@version | @scope/]... [--ignore-engines] [--pattern]
- Remove package:
yarn remove <package...>
- List all packages and their dependencies:
yarn list [--depth] [--pattern]
- Run the script:
yarn run [script] [<args>]