How to Install, uninstall, and upgrade Yarn in MacOS

Yarn is a package manager for Node libraries similar to npm.

This tutorial explains about to install, uninstall, and upgrade the yarn package manager on macOS

Homebrew is a package manager that install the software in MACOS.

how to install Yarn on MacOS

There are multiple ways we can install yarn on macOS

  • Using the brew command

First, the brew command should work in terminal.

brew --version
Homebrew 4.0.3

If the above commands show the version number, Then the brew installed

To install yearn on MacOS

First, use the command brew outdated

brew outdated

It lists outdated packages.

Next, Run `brew update to update all packages to the latest version

brew update

Next, Install the yarn package using the below command

brew install yarn

If you want to install a specific version

brew install [email protected]
  • using the npm command

yarn is an npm library tool that can be installed with the npm install command.

npm install --global yarn

Installed globally using --global

  • Using MacPorts

Macports is an opensource for build and installing third-party tools on MacOS

sudo port install yarn
  • Using Shell Scripts Run shell scripts using curl command with version as given commands
curl -o- -L https://yarnpkg.com/install.sh | bash
curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 3.2.1

Once the yarn is installed, You can check the yarn version

yarn --version
3.2.1

The above command returns the installed version number

uninstall yarn in macOS

There are multiple ways you can do this.

The below approaches selected based on yarn installation

  • npm uninstall command removes and uninstalls yarn from a Maco
npm uninstall -g yarn
  • brew uninstall command removes and uninstalls yarn from a MacOS
brew uninstall yarn

if the above commands give an error, use —force

brew uninstall --force yarn

How to upgrade the yarn version to the latest on MacOS Terminal

If the yarn is installed with brew, Follow the command to upgrade

brew upgrade yarn

For npm users,

npm upgrade --global yarn

Another way, that works for all installation methods

yarn policies set-version

It updates the yarn to the latest version

yarn policies set-version 3.2.0

It updates the yarn to version 3.2.0

Find the installed location in MacOS

Sometimes, Your macOS has multiple versions of yarn installed.

You can check using the below command

which yarn
/usr/local/bin/yarn

If there are multiple versions installed in local, you can set using brew unlink yarn

brew unlink yarn
brew link yarn@newversion

Issues and errors in the yarn package manager

Sometimes, you will get errors while installing/uninstall

Please make sure that you have sudo rights in doing the above operations

For example, If an error or issue is found in the yarn installation

run with the below command

sudo npm install --global yarn