How to Install Yarn on Debian 11 / Debian 10
Here, we will see how to install Yarn on Debian 11 / Debian 10.
Install Node.js and npm on Debian
To install Yarn on Debian, you will need npm (Node Package Manager), which in turn requires Node.js. So, install both Node.js and npm on Debian using the steps mentioned in the below links.
I recommend you install the Node.js v14.x and npm version that comes with Node.js.
READ: How to install Node.js on Debian 11
READ: How to install Node.js on Debian 10
Check the Node.js version (node -v) and npm version (npm -v) post the installation.
Install Yarn on Debian
Starting from Yarn v2, the Yarn is installed and managed on a by-project basis. But, first, you will need to install the global Yarn binary that you will use to spawn the project-based Yarn version.
sudo npm install -g yarn
Once you have installed Yarn global binary, check the Yarn version with the yarn -v command.
The above output confirms that the expected global version is installed on the system.
Now, head over to your project directory.
Install the latest Yarn binary for your project.
yarn set version berry
Now, check the Yarn version with the yarn -v command.
The above output confirms that your project has the latest version of Yarn.
Yarn is now ready for your projects, and you can start using it. Here are some of the common commands you will need for your project work.
Find the list of commands.
To start a new project, use the yarn init command. This command will ask you series of questions related to your project. You can either answer a question or press enter to use the default values.
mkdir my_project && cd my_project yarn init
In the end, the yarn init command will place package.json, which contains the project information you provided, and yarn.lock, which contains all the information about project dependencies.
To add a dependency for your project, use yarn add followed by the package name. This command will download and install the dependency package and updates the dependency information in package.json and yarn.lock.
yarn add [package] yarn add [package]@[version] yarn add [package]@[tag]
To install all the dependencies of your projects.
yarn yarn install
To upgrade an existing dependency in your project, use yarn up followed by package name.
yarn up [package] yarn up [package]@[version] yarn up [package]@[tag]
In case you want to remove a dependency you no longer needed in the project.
yarn remove [package]
You can update Yarn to the latest version at any time with the below command. This command will download the most recent binary from Yarn’s official site and install it in your project.
yarn set version latest
That’s All. I hope you have learned how to install Yarn on Debian 11 / Debian 10. You can visit the Yarn documentation page to learn more about Yarn.