Yarn is a JavaScript package manager for Node.js projects. It caches packages locally for faster installs, verifies packages with checksums and maintains consistent dependency trees across environments.
You will install Yarn globally on your Linux system using either npm or cURL. Once installed, you can manage Node.js packages across all your projects and control which Yarn version you use.
Before installing Yarn, you should check whether it already exists on your system. This prevents conflicts and shows you which version is currently active.
Run this command to check for Yarn:
yarn --version
If Yarn is installed, you will see a version number. If you see “command not found”, Yarn is not installed and you can proceed with one of the installation methods below.
Installing Yarn globally with npm makes it available to all Node.js projects on your system. The -g flag installs Yarn system-wide rather than in a single project directory.
sudo npm install -g yarn
yarn --version
Yarn is now installed and ready to manage packages in your Node.js projects.
If npm is not available on your system, you can download and install Yarn directly using cURL. This method fetches the latest Yarn installation script and runs it automatically.
curl --compressed -o- -L https://yarnpkg.com/install.sh | bash
source ~/.bashrc
If you use a different shell, replace ~/.bashrc with your shell’s configuration file, such as ~/.zshrc for Zsh.
yarn --version
Yarn is now installed and configured in your shell environment.
After installing Yarn, you can control which version your system uses. This allows you to pin a specific version for compatibility or update to the latest release.
To set a specific Yarn version, run:
yarn set version [version_number]
Replace [version_number] with the version you need, such as 1.22.19.
To update to the latest Yarn version, run:
yarn set version latest
This fetches and installs the most recent stable release.
You have installed Yarn on your Linux system and verified it works correctly. You can now use Yarn to manage Node.js packages across all your projects, with the option to control which version you run.
If you are setting up a Node.js development environment, you might also want to install MERN stack on AlmaLinux. For more control over your development environment, explore our VPS hosting options.
Get scalable resources with our VPS hosting with root access and optional software.
Get VPS HostingPerfect for websites and small businesses unlimited bandwidth with cPanel hosting.
Get cPanel Hosting