Skip to content
Related Articles

Related Articles

Improve Article

How to Install Yarn in MacOs/Ubuntu/Windows?

  • Last Updated : 18 May, 2021

Prerequisite: Difference between npm and yarn

Yarn in layman’s term is a package manager that can be used in your code or a project that is currently being built, what yarn does is it helps to share the code with fellow mates or within a community of developers, and they can even run the project that we are building on their end. 

But how actually is that code shared with other people, well that’s done by sharing the code files that are used to develop the project and with a package.json file, and this package.json file describes what all yarn package is used in the project, also which are required with its version used while developing the project. So, what the other fellow mate can do is install yarn on his/her machine and do 

yarn install 

To install all the dependencies and packages required to get started with the project.

MacOS

Method 1: Using NPM.



In the OS X terminal you need to type:

npm install --global yarn

NOTE: You will need to have NPM (Node package manager pre-installed on the pc)

If some error comes you need to give admin privileges to the terminal so that it can access npm already installed on your pc.

How to install Yarn in MacOs/Ubuntu/Windows?

installing yarn using npm on macOS

Method 2: Using HomeBrew Package Manager:

brew install yarn

Method 3: Using curl:

You need to type the following command in the terminal

curl -o- -L https://yarnpkg.com/install.sh | bash

NOTE: the above command works for both Linux and macOS.

How to install Yarn in MacOs/Ubuntu/Windows?



Ubuntu/Debian (Linux)

Method 1: Using npm manager.

It’s valid to use the standard method to install with npm, using the following commands in the terminal

npm install --global yarn

How to install Yarn in MacOs/Ubuntu/Windows?

Method 2: Using curl.

Step 1: You can install it with the Debian package repository by first configuring the repository first using the following commands.

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
How to install Yarn in MacOs/Ubuntu/Windows?

Demo of the above 2 commands

Step 2: And then once after successful install of the above command use

sudo apt install yarn

installing yarn and checking the version installed

Windows

Method 1: Using msi file.

Using the .msi file which can be downloaded from here (from the official yarn-site)

Source: yarn official site

Method 2: Using chocolatey package manager.

Step 1: Install choco package in your windows, for that you need to go here.



Basically, you need to type the following command shown below with administrative privileges

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString(‘https://chocolatey.org/install.ps1’))

Step 2: After installing head over to PowerShell and follow the instructions below.

Open up the windows PowerShell or any preferable terminal and type the following command

choco install yarn

Yarn installation 

Successful install of yarn

CentOS / Fedora / RHEL

Step 1: Using RPM package manager type the following command in the terminal.

curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo

Step 2: After performing the above steps type the following commands in the terminal

curl --silent --location https://rpm.nodesource.com/setup_12.x | sudo bash -

Step 3: At last, type the following to install yarn completely in the machine

sudo yum install yarn
My Personal Notes arrow_drop_up
Recommended Articles
Page :