Yarn commands cheatsheet
In this article, I will describe the basic Yarn commands and their usage, using the popular lodash
package as an example.
To find out why it's better to use Yarn instead of NPM, please read this article where I compared these tools.
Install the latest version of the package:
yarn add lodash@latest
Install the latest version of the package and save to devDependencies
instead of dependencies
:
yarn add -D lodash@latest
Install the latest version of the package globally:
yarn add global lodash@latest
Install specific version of the package (eg 3.10.1
):
yarn add [email protected]
Install caret version of the package (eg ^4.13.1
).
When a caret version of a package is specified, it sets certain rules for updating the dependency when installing new package versions. In this case, "^4.13.1" means that Yarn can install any minor or patch version that is compatible with version 4.13.1 but should not exceed major version 5.
yarn add lodash@^4.13.1
Hint: use NPM repositories to browse the list of versions for your package. For example: lodash.
Uninstall the package:
yarn remove lodash
Uninstall the globally installed package:
yarn global remove lodash
The command `yarn set version`` allows you to switch the Yarn version at the project level.
Activate the latest stable version (4.x at the time of writing this article):
yarn set version stable
Activate the latest 3.x version:
yarn set version 3.x
Activate classic (old) 1.x version:
yarn set version classic
You may also like