DebianDebian Based

How To Install Yarn on Debian 12

Install Yarn on Debian 12

In this tutorial, we will show you how to install Yarn on Debian 12. JavaScript has firmly established itself as a dominant force in modern web development. With its expansive ecosystem of libraries and frameworks, managing JavaScript packages efficiently is paramount. Enter Yarn, a powerful package manager that simplifies package management and enhances the overall development workflow.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Yarn package manager for JavaScript on a Debian 12 (Bookworm).

Prerequisites

  • A server running one of the following operating systems: Debian 12 (Bookworm).
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for Yarn.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Yarn on Debian 12 Bookworm

Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt commands in the terminal:

sudo apt update
sudo apt install curl dirmngr apt-transport-https lsb-release ca-certificates

This command will refresh the repository, allowing you to install the latest versions of software packages.

Step 2. Installing Node.js

Yarn relies on Node.js to function correctly. Let’s install Node.js from the official repository:

sudo apt install nodejs

Step 3. Installing Yarn on Debian 12.

First, Add the Yarn repository to your system’s sources list:

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

Update the package list and install Yarn:

sudo apt update
sudo apt install yarn

Verify that Yarn was installed successfully by running:

yarn --version

Step 4. Install and remove packages using Yarn.

  • Installing Packages with Yarn

To install packages using Yarn, follow these steps:

1. Navigate to Your Project Directory

Open your terminal and navigate to the root directory of your project where you want to install the packages. Use the cd command to change directories:

cd /path/to/your/project

2. Initialize Your Project (if not already done)

If your project is not already initialized with a package.json file (which typically holds information about your project and its dependencies), you can create one by running:

yarn init

Follow the prompts to provide information about your project, or simply press Enter to accept the default values.

3. Install Packages

To install one or more packages, you can use the yarn add command followed by the package names. For example, to install the popular package “axios,” you would run:

yarn add axios

You can also install multiple packages at once by separating their names with spaces:

yarn add package1 package2 package3

Yarn will fetch and install the specified packages and add them to your package.json file as dependencies.

4. Install Development Dependencies

If you want to install packages as development dependencies (e.g., for testing or development purposes), you can use the --dev flag:

yarn add --dev package-name

5. Specifying Package Versions

By default, Yarn installs the latest version of a package. To specify a different version or range of versions, you can include it in the command:

yarn add package-name@version

For example, to install version 2.0.0 of a package:

yarn add package-name@2.0.0

6. Installing All Dependencies

If you have a package.json file with listed dependencies and you want to install all of them at once, you can simply run:

yarn install

Yarn will read the dependencies from your package.json and install them.

  • Removing Packages with Yarn

To remove packages that you no longer need in your project, follow these steps:

1. Remove Packages

Use the yarn remove command followed by the package names you want to remove. For example, to remove “axios“:

yarn remove axios

Yarn will uninstall the specified package and update your package.json file accordingly.

2. Removing Development Dependencies

If you want to remove a package that was installed as a development dependency, use the --dev flag:

yarn remove --dev package-name

Congratulations! You have successfully installed Yarn. Thanks for using this tutorial to install the latest version of the Yarn package manager on Debian 12 Bookworm. For additional help or useful information, we recommend you check the official Yarn website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button