Install Yarn on Debian 11

|
Last Updated:
|
|

Follow through this guide to learn how to install Yarn on Debian 11. Yarn is an acronym for Yet Another Resource Navigator. Yarn is a fast, secure and reliable JavaScript package manager that is compatible with npm registry and can be used with npm.

Installing Yarn on Debian 11

There are multiple ways in which you can install:

Install Yarn via npm

In order to install Yarn via NPM, you need to have NPM installed.

You can install latest Nodejs Package Manager on Debian 11. Nodejs 16.x is the current stable release based on the releases page.

apt install curl sudo -y
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -

Next, run the command below to install Node.js 16.x and npm

apt install nodejs

Check Nodejs package manager version

npm -v
7.20.3

Now that NPM is already installed, you can then install Yarn via npm using the command below;

npm install --global yarn 

Checking the version of installed Yarn on Debian 11;

yarn -v
1.22.11

Uninstall Yarn

If for some reasons you want to uninstall Yarn, you can use the command below;

npm uninstall -g yarn

Install Yarn via APT

To install Yarn via APT, you need to ass the Yarn APT repo as shown in the commands below;

curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
apt update
apt install yarn

Please note this method may not get you the latest version of yarn though.

The command above installs both Yarn and NPM;

yarn -v
1.22.5
npm -v
7.20.3

Install Yarn via install Script

The easiest way to install Yarn is via install script. However, note that also, the script installation may not install the latest version of Yarn.

To install Yarn via the install script, you need to have Nodejs installed.

curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
apt install nodejs

You can simply run the command below to download and run the Yarn installation script.

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

Sample command output;

...
> GPG signature looks good
> Extracting to ~/.yarn...
> Adding to $PATH...
> Successfully installed Yarn 1.22.5! Please open another terminal where the `yarn` command will now be available.

The script don’t install yarn globally and hence, it can only be used under your profile.

less ~/.bashrc
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"

Source your bashrc and verify the Yarn version:

source ~/.bashrc
yarn -v

That marks the end of our tutorial on how to install Yarn on Debian.

Read more on Yarn Documentation page.

Other Tutorials

Install PHP 7.1/7.2/7.3/7.4 on Debian 11

Install PHP 8 on Debian 11

Install Latest Nodejs on Rocky Linux 8

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
gen_too
Co-founder of Kifarunix.com, Linux Tips and Tutorials. Linux/Unix admin and author at Kifarunix.com.

Leave a Comment