Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Install Yarn on Ubuntu

Install Node.js, add Yarn with npm and learn the common Yarn commands.

VPS and Cloud Servers1 min read6 steps5 screenshots

Prerequisites

Update Ubuntu:

sudo apt update && sudo apt upgrade -y
Updating Ubuntu

You need sudo rights. Install Node.js and npm:

sudo apt install nodejs npm -y
Installing Node.js and npm

Key features of Yarn

  1. Fast. Downloads packages in parallel.
  2. Secure. Checks package integrity.
  3. Reliable. The yarn.lock file fixes the versions.
  4. Offline install. Reuses cached packages.
  5. Good network use. Retries and limits requests.
  6. Better dependency resolution.
sudo npm install --global yarn
Installing Yarn globally

Check:

yarn --version
The Yarn version

Install from the Ubuntu repository

On Ubuntu the yarn package name can point to a different tool (cmdtest), so the npm method is safer. The repository package is named yarnpkg on newer releases:

sudo apt install yarnpkg
Installing Yarn with apt

Common commands

  • yarn init creates a new project with a package.json.
  • yarn add [package] adds a package.
  • yarn remove [package] removes a package.
  • yarn install installs all the dependencies.
  • yarn upgrade updates the packages.
  • yarn run [script] runs a script from package.json.

Quick recap

  • Install Node.js, then sudo npm install --global yarn.