How to Install Yarn on Debian 9
3 min read
In this tutorial, we will guide you on how to install Yarn on a Debian 9 system via the Yarn APT package repository. The official Yarn repository is consistently maintained and provides the most up-to-date version.
Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges.
Installing Yarn on Debian
Follow these step below to install Yarn on your Debian 9 system:
The first step is to enable the Yarn repository. Start by importing the repository’s GPG key using the following
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
Use the following command to enable the Yarn APT repository:
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
Once the repository is enabled, update the package index and install Yarn, with:
sudo apt update
sudo apt install yarn
If you already don’t have Node.js installed on your system, the command above will install it. Those who are using nvm can skip the Node.js installation with:
sudo apt install --no-install-recommends yarn
Verify the installation by printing the Yarn version number:
At the time of writing this article, the latest version of Yarn is version
Now that you have Yarn installed on your Debian system, the next step is to explore some of the most common Yarn commands.
Creating a new project
To create a new Yarn project use the
yarn init command as shown below:
yarn init my_yarn_project
The init script will ask you several questions. You can either answer or press
enter to use the default values.
yarn init v1.17.3 question name (vagrant): Linuxize question version (1.0.0): 0.0.1 question description: Testing Yarn question entry point (index.js): question repository url: question author: Linuxize question license (MIT): question private: success Saved package.json Done in 20.18s.
Once completed, the script will create a basic
package.json file that will contain the information you provided. You can later open and edit this file.
If you want to use another package in your project, you need to add it to the project dependencies. To do so, use the
yarn add command followed by the package name:
yarn add [package_name]
The command above will also update the
yarn.lock files so anyone working on this project when running
yarn will get the same dependencies.
You can also specify the package version or package tag:
yarn add [package_name]@[version_or_tag]
To upgrade the packages, use one of the following commands:
yarn upgrade [package_name]
yarn upgrade [package_name]@[version_or_tag]
If no package name is given, the command will update the project dependencies to their latest version according to the version range specified in the package.json file. Otherwise, only the specified packages are updated.
To remove a dependency use the
yarn remove command followed by the package name:
yarn remove [package_name]
This command will also update the project’s
Installing all project dependencies
To install all project dependencies that are specified in the
package.json file run:
We have shown you how to install yarn on your Debian 9 machine. For more information about yarn visit the Yarn documentation page.
If you have any questions or feedback, feel free to comment below.