Modern Installation with Yarn/pnpm


Previously, the Yarn package manager was installed in various ways such as running npm install -g yarn.

Once installed, you could always use the yarn CLI globally in the terminal.


With the development of the times, the installation method of Yarn has also changed. The official website states that the preferred way to manage Yarn is by-project and through Corepack. The reason being "just as project dependencies are locked, the package manager itself should also be locked".

The advantage of using Corepack is that it allows for faster CLI updates.


Starting from Node.js v16.9.0, v14.19.0, Corepack is included. However, this feature is currently in the experimental stage and is disabled by default. Therefore, you need to run corepack enable to enable it, and then you can use the yarn command.


Run yarn exec env, if you get a series of path outputs, it means Corepack has been installed correctly, which can quickly check if Corepack is enabled. If not, please refer to Troubleshooting for solutions.


Whenever you want to update Yarn to the latest version, simply run:

yarn set version stable
yarn install

Then, Yarn will configure your project to use the latest stable binary.


Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.