How to Install Yarn

If you’ve never heard of Yarn, it’s a new package manager for JavaScript. It’s similar to NPM in that it allows you to install and manage dependencies for your project. The big difference is that yarn uses an immutable lockfile (yarn.lock) and installing dependencies is faster and more reliable, thanks to multiple registries worldwide.

What is Yarn?

Yarn is a cutting-edge JavaScript package management technology mostly used for Node.js applications. When installing, configuring, updating, and uninstalling npm packages, yarn could well be utilized. It aids with solving difficulties like network connection, accelerating the installation procedure, etc.

SEE: How To Create a Slack Channel

Node Version Manager (NVM)

NVM is a tool for managing multiple versions of Node.js and has become increasingly popular with developers who work on projects that use different versions of Node.js depending on its runtime requirements. Installing nvm involves running a shell script that clones a git repository containing nvm’s source code into ~/.nvm.

After cloning this repository, Add the line below to your ~/.bash profile, ~/.zshenv, or ~/.config/fish/config. Doing so will cause nvm’s initialization scripts to be run when opening new shellsaber every time upon logging out and back in again.

Benefits of Using Yarn

Yarn has a number of advantages over other methods:

  • It is much faster
  • The dependencies are downloaded parallel which leads to slashed installation time
  • Provides an offline mode for when you can’t get online, or the registry is down.

How do I install yarn?

If you are using a Mac, the easiest way to install Yarn is through Homebrew. Simply run brew update && brew install yarn on your terminal, and it will be installed in minutes!

For Windows users, you can install Yarn by following these steps:

  1. Download the installer from here
  2. Run the downloaded .msi file  
  3. Follow the prompts in the setup wizard    
  4. Verify your installation by opening a Command Prompt or PowerShell terminal window and typing “yarn –version“.

You should see something like 1.22

How To Install Yarn Globally

There are a variety of ways to install Yarn. Depending on your system, you can install it via Homebrew, Chocolatey, or Scoop. On Linux systems, you can also use the curl command to download and run the installer script. To do this, first ensure that curl is installed, then type the following in your terminal:

How to Install Yarn

Installing Yarn on CentOS 7

Step 1: Make sure your system is current. This is the first step

Step 2: CentOS Yarn installation

Install Node.js on your server first, then use the curl command below to activate the Nodesource repository before you can install Yarn.

How To Install Yarn Globally

Type the following to install the Node.js package

install the Node.js package

Next, carry out the following instructions to activate the Yarn repository and import its GPG key:

Yarn may be installed after the repository has been loaded by running:

Now that the installation is complete, you may run the following command to verify:

Install Yarn on Ubuntu Using APT Package Manager

Usually, Yarn is not included in the standard Ubuntu repository. Therefore, installing Yarn is as simple as adding the official Yarn repository to the list of sources.

Install Yarn on Ubuntu Using APT Package Manager

Yarn will be set up on your Ubuntu device after doing this.

Using Yarn

There are two ways of using Yarn – via the CLI (Command Line Interface) or from within an IDE such as WebStorm/IntelliJ IDEA Ultimate Edition by JetBrains. Before you do so, however, you will need some dependencies installed.

Installing dependencies

To add a dependency, simply cd into your project folder, then type in yarn add followed by the name of what you wish to install i.e.:yarn add react.

This will install React under dependencies directory./ projects root folder; OR if adding a specific version: yarn add [email protected]^1..10, where caret ^ indicates any minor versions below specified number e.g., v1 while tilde ~ allows flexibility with patch versions only everything else being equal(eTweaky stuff).

Making Use Of Yarna

Create a new Yarn project use yarn init:

Making Use Of Yarna

Adding the dependencies installed in the previous step:

Adding dependencies on Yarn

Upgrading dependency (optional):

Installing all project dependencies:

How to upgrade yarn

To date, only two versions of Yarn have been released, and developers recommend migrating to the latest versions.

npm by default installs the older version of Yarn. A simple way of confirming this is running “yarn –version” and if the output is in the format, 1.x.x (like 1.22.10) then you are on the older version.

SEE: How To Update Kindle Software

To migrate a specific project to the new version, go to the specific project directory and execute

Migrate yarn

Note: “Berry” is the codename for the Yarn 2 release line.

To permanently upgrade to the newer version, run

yarn latest version

Congratulations! You have successfully installed Yarn. Now you know how to install Yarn which you can use to manage your code snappily with ease. To learn more about Yarn and how to use it, you can read the official Yarn documentation.

For more installation guides, read How To Install WordPress on GoDaddy.

Leave a Comment