DEV Community

Cover image for How to Install Yarn on Linux Mint (Using NVM) for React and Vite Projects
Sunil Pradhan
Sunil Pradhan

Posted on

How to Install Yarn on Linux Mint (Using NVM) for React and Vite Projects

If you're learning React on Linux Mint, one of the first things you'll need is a JavaScript package manager. While npm comes bundled with Node.js, many React projects also use Yarn.

In this guide, I'll show you how I installed Yarn on Linux Mint after installing Node.js using NVM (Node Version Manager). This is the recommended approach because it keeps your Node.js and package manager versions organized and easy to update.

Prerequisites

Before installing Yarn, make sure you already have:

  • Node.js installed using NVM
  • npm (installed automatically with Node.js)

You can verify your installation by running:

node -v
npm -v
which node
which npm
Enter fullscreen mode Exit fullscreen mode

My output looked like this:

Yarn Prerequisites

If your node and npm paths point to your .nvm directory, then you're ready to install Yarn.

Why I Didn't Install Yarn with npm

Earlier, it was common to install Yarn globally using:

npm install -g yarn
Enter fullscreen mode Exit fullscreen mode

However, if you're using a modern version of Node.js (like Node.js 18, 20, 22, or newer), there's a better way.

Node.js now includes Corepack, a tool that manages package managers like Yarn and pnpm. This means you don't need to install Yarn globally with npm.

Step 1: Check if Corepack is Available

Run:

corepack --version
Enter fullscreen mode Exit fullscreen mode

If you see a version number, Corepack is already installed.

Step 2: Enable Corepack

Enable it by running:

corepack enable
Enter fullscreen mode Exit fullscreen mode

You only need to do this once.

Step 3: Install the Latest Stable Version of Yarn

Run:

corepack prepare yarn@stable --activate
Enter fullscreen mode Exit fullscreen mode

Depending on your Corepack version, you can also use:

corepack use yarn@stable
Enter fullscreen mode Exit fullscreen mode

Both commands activate the latest stable version of Yarn.

Step 4: Verify the Installation

Finally, check the installed version:

yarn --version
Enter fullscreen mode Exit fullscreen mode

If a version number is displayed, Yarn has been installed successfully.

check yarn installed version

Verify Everything

You can also confirm your complete setup with:

node -v
npm -v
corepack --version
yarn --version
Enter fullscreen mode Exit fullscreen mode

Everything should return version numbers without any errors.

yarn complete setup

Creating Your First React Project

Once Yarn is installed, creating a new React project with Vite is simple:

yarn create vite my-app
Enter fullscreen mode Exit fullscreen mode

Move into the project folder:

cd my-app
Enter fullscreen mode Exit fullscreen mode

Install the project dependencies:

yarn
Enter fullscreen mode Exit fullscreen mode

Start the development server:

yarn dev
Enter fullscreen mode Exit fullscreen mode

Open the URL shown in the terminal (usually http://localhost:5173) to see your React application running.

Why This Method Is Better

Using NVM together with Corepack offers several benefits:

  • Keeps Node.js versions easy to manage.
  • Uses the officially recommended way to install Yarn.
  • Avoids installing Yarn globally with npm.
  • Makes switching between different JavaScript projects much easier.
  • Works well with modern React and Vite applications.

Final Thoughts

If you're using Linux Mint and have installed Node.js through NVM, installing Yarn with Corepack is the cleanest and most future-proof approach.

The setup only takes a few minutes, and once it's done, you're ready to build modern React applications with Vite.

In my next post, I'll show you how to create your first React project using Vite and explain the folder structure so you can understand what each file does.

Top comments (0)