Yarn is an alternative JS package manager Node.js projects. It was created to solve some of the issues with npm (Node Package Manager). And, is focused on speed, security, consistency, while npm has caught up in many areas Yarn is still very popular among developers and is likely to stay around for awhile longer.
First off check which version (if any) is installed, you can do this with the following command.
yarn --version
To use Yarn across all projects, you need to install it globally. You can do this using npm which comes with Node.js. Use the -g flag to install Yarn globally:
1. Start by installing Yarn with npm we use the command below with a -g flag to indicate it is a global install.
sudo npm install -g yarn
2. Afterwards you can verify the current Yarn version with the command shown below,
yarn –version
3. If you want to set a specific version you can use the set version command.
yarn set version "version_number"
4. Finally to revert any set version changes you can set Yarn back to the latest up to date package with the following:
yarn set version latest
For systems that don’t have npm, have more stricter install requirements or simply want a bit of a shortcut we can use cURL to download and install the latest Yarn version using the command below.
curl --compressed -o- -L https://yarnpkg.com/install.sh | bash