AlmaLinuxRHEL Based

How To Install Yarn on AlmaLinux 10

Install Yarn on AlmaLinux 10

Setting up a modern JavaScript development environment on AlmaLinux 10 requires essential tools that streamline package management and dependency handling. Yarn, Facebook’s JavaScript package manager, stands as one of the most crucial utilities for developers working with Node.js applications. This comprehensive guide demonstrates multiple methods to install Yarn on AlmaLinux 10, ensuring you can choose the approach that best fits your specific requirements and system configuration.

AlmaLinux 10 provides an enterprise-grade foundation for development environments, combining stability with cutting-edge features. When paired with Yarn’s advanced package management capabilities, developers gain access to faster dependency installations, deterministic builds, and enhanced security features that traditional package managers cannot match.

What is Yarn and Why Use It?

Yarn (Yet Another Resource Navigator) represents a significant advancement in JavaScript package management technology. Developed by Facebook to address npm’s limitations, Yarn introduces several compelling advantages that make it the preferred choice for professional development teams.

The package manager excels in parallel downloads, simultaneously fetching multiple dependencies to dramatically reduce installation times. Unlike traditional sequential downloads, Yarn’s intelligent caching system stores packages locally, enabling offline installations and faster subsequent builds. The deterministic installation process creates identical dependency trees across different environments through the yarn.lock file, eliminating the infamous “works on my machine” problem.

Security enhancements built into Yarn include automatic integrity verification and comprehensive audit capabilities that detect vulnerable packages before they compromise your applications. These features, combined with workspace support for monorepo management, position Yarn as an indispensable tool for modern JavaScript development workflows.

Prerequisites and System Requirements

Before installing Yarn on AlmaLinux 10, ensure your system meets the necessary requirements. Root or sudo privileges are essential for system-wide installations and repository modifications. Network connectivity remains crucial for downloading packages and accessing remote repositories during the installation process.

Your AlmaLinux 10 system should have adequate disk space for package installations and cache storage. While Yarn itself requires minimal resources, the packages you’ll manage may have substantial storage requirements. Consider allocating at least 1GB of free space for optimal performance.

Node.js and NPM form the foundational requirements for Yarn installation. Most installation methods depend on a functional Node.js environment, making these prerequisites mandatory for successful Yarn deployment.

Pre-Installation Setup

Updating AlmaLinux 10 System

System updates establish a stable foundation for software installations. Execute the following command to refresh package repositories and install available updates:

sudo dnf update -y

This command ensures your system has the latest security patches and package definitions. The process may take several minutes depending on the number of available updates and your network speed.

If your system lacks the EPEL (Extra Packages for Enterprise Linux) repository, install it using:

sudo dnf install epel-release -y

Installing Node.js and NPM

Node.js installation serves as the cornerstone for Yarn functionality. AlmaLinux 10 provides multiple Node.js versions through its modular package system. Check available Node.js streams with:

sudo dnf module list nodejs

Install the default Node.js module and npm package manager:

sudo dnf module install nodejs:18/common -y

Verify the installation by checking versions:

node --version
npm --version

Expected output should display version numbers confirming successful installation. These commands validate that both Node.js runtime and npm package manager are properly configured and accessible system-wide.

Method 1: Installing Yarn Using RPM Repository

Adding Yarn Official Repository

The RPM repository method provides the most reliable approach for Yarn installation on AlmaLinux 10. This method ensures automatic updates and maintains consistency with your system’s package management infrastructure.

Create the Yarn repository configuration file:

sudo tee /etc/yum.repos.d/yarn.repo <<EOF
[yarn]
name=Yarn Repository
baseurl=https://dl.yarnpkg.com/rpm/
gpgcheck=1
gpgkey=https://dl.yarnpkg.com/rpm/pubkey.gpg
enabled=1
EOF

This configuration establishes a trusted connection to Yarn’s official repository while enabling GPG signature verification for enhanced security. The repository configuration persists across system reboots and dnf operations.

Import the GPG signing key manually if automatic import fails:

sudo rpm --import https://dl.yarnpkg.com/rpm/pubkey.gpg

Refresh the package cache to incorporate the new repository:

sudo dnf makecache

Installing Yarn Package

With the repository configured, install Yarn using the DNF package manager:

sudo dnf install yarn -y

The installation process downloads Yarn and its dependencies, typically completing within minutes. DNF automatically resolves dependencies and handles potential conflicts with existing packages.

During installation, you may encounter GPG key verification prompts. Accept these prompts to proceed with the installation. The package manager validates signatures to ensure package authenticity and integrity.

Monitor the installation output for any error messages or warnings. Successful installations conclude with a “Complete!” message and return to the command prompt.

Verification of Installation

Verify the Yarn installation by checking its version:

yarn --version

A successful installation displays the current Yarn version number. Additionally, test basic functionality with:

yarn --help

This command reveals available Yarn commands and options, confirming that the installation completed successfully and Yarn is ready for use in your development projects.

Method 2: Installing Yarn Using NPM

Prerequisites Check

Before proceeding with NPM installation, verify that Node.js and NPM are properly installed and accessible. Execute version checks to confirm functionality:

node --version
npm --version

Both commands should return version numbers. If either command fails, return to the pre-installation setup section to resolve Node.js installation issues.

Check NPM’s global installation directory permissions to avoid potential installation conflicts:

npm config get prefix

Global NPM Installation

Install Yarn globally using NPM with the following command:

sudo npm install --global yarn

The global installation makes Yarn available system-wide for all users. NPM downloads Yarn from the official registry and installs it in the global packages directory.

Alternative installation syntax produces identical results:

sudo npm install -g yarn

Monitor the installation progress through NPM’s output. The process typically completes quickly since Yarn’s package size remains relatively small compared to larger development frameworks.

Global installations may require elevated privileges depending on your system’s NPM configuration. Use sudo when encountering permission-related errors during installation.

Post-Installation Verification

Confirm the NPM-based installation by checking Yarn’s version:

yarn --version

Test basic functionality to ensure proper installation:

yarn init --help

This command should display help information for Yarn’s project initialization feature, indicating successful installation and configuration.

Method 3: Installing Yarn Using Installation Script

Download and Execute Script

The installation script method provides a direct approach that bypasses package managers entirely. This method works well in environments where repository access is restricted or when you need the latest Yarn version immediately.

Download and execute the installation script:

curl -o- -L https://yarnpkg.com/install.sh | bash

The script automatically detects your system configuration and downloads the appropriate Yarn binary. It configures PATH variables and establishes the necessary symlinks for system-wide access.

Security considerations are important when executing remote scripts. Always review script contents before execution in production environments. The official Yarn installation script undergoes regular security audits and maintains a strong security track record.

Path Configuration

The installation script typically adds Yarn to your PATH automatically. However, manual configuration may be necessary in some cases. Add Yarn’s bin directory to your PATH:

export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"

Make this change permanent by adding it to your shell profile:

echo 'export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

Verification and Testing

Verify the script-based installation:

yarn --version

Test basic operations to ensure full functionality:

yarn help

Getting Started with Yarn

Creating Your First Yarn Project

Project initialization with Yarn creates the foundation for JavaScript applications. Navigate to your desired project directory and run:

mkdir my-yarn-project
cd my-yarn-project
yarn init

The interactive initialization process prompts for project details including name, version, description, and entry point. Yarn creates a package.json file containing your project’s metadata and dependency specifications.

Best practices for project initialization include using descriptive names, semantic versioning, and comprehensive descriptions. These elements improve project maintainability and facilitate collaboration with team members.

The generated package.json file serves as your project’s configuration center, controlling dependencies, scripts, and metadata. Review and customize this file to match your project’s specific requirements.

Basic Yarn Commands and Operations

Dependency management forms Yarn’s core functionality. Install project dependencies using:

yarn install

Add new packages to your project:

yarn add lodash
yarn add --dev jest
yarn add axios@^0.21.0

These commands demonstrate installing runtime dependencies, development dependencies, and specific package versions respectively. Yarn automatically updates package.json and creates or updates the yarn.lock file.

Package upgrades maintain current dependencies:

yarn upgrade
yarn upgrade lodash
yarn upgrade lodash@latest

Remove unnecessary packages:

yarn remove lodash

List installed packages and their versions:

yarn list
yarn list --depth=0

The yarn.lock file ensures deterministic installations by recording exact package versions and dependency trees. Never manually edit this file; let Yarn manage it automatically to maintain consistency across environments.

Advanced Yarn Configuration and Management

Yarn Configuration Options

Global configuration settings customize Yarn’s behavior across all projects. View current configuration:

yarn config list

Modify configuration values:

yarn config set registry https://registry.npmjs.org/
yarn config set cache-folder /tmp/yarn-cache

Project-specific configurations override global settings within individual projects. Create a .yarnrc file in your project root:

echo "registry https://custom-registry.company.com/" > .yarnrc

Package Management Best Practices

Version pinning strategies ensure consistent builds across environments. Use exact versions for critical dependencies and ranges for less critical packages. The yarn.lock file provides automatic exact version management while allowing flexibility in package.json.

Security auditing identifies vulnerable dependencies:

yarn audit
yarn audit --level moderate

Address security vulnerabilities promptly by upgrading affected packages or finding alternative solutions.

Performance Optimization

Cache utilization significantly improves installation speeds. Yarn automatically caches downloaded packages, but you can manage cache manually:

yarn cache list
yarn cache clean

Enable parallel installations in your configuration to maximize download efficiency:

yarn config set network-concurrency 16

Troubleshooting Common Issues

Installation Problems

Repository access issues often stem from network connectivity or firewall restrictions. Verify internet connectivity and proxy configurations:

curl -I https://dl.yarnpkg.com/

GPG key verification failures can be resolved by manually importing keys:

sudo rpm --import https://dl.yarnpkg.com/rpm/pubkey.gpg

Clear DNF cache if repository metadata becomes corrupted:

sudo dnf clean all
sudo dnf makecache

Permission-related errors typically occur during global installations. Use sudo for system-wide installations or configure NPM to use a different global directory:

mkdir ~/.npm-global
npm config set prefix '~/.npm-global'

Runtime Issues

Path configuration problems prevent Yarn command recognition. Verify Yarn’s location and ensure it’s in your PATH:

which yarn
echo $PATH

Version conflicts between npm and Yarn can cause unexpected behavior. Use one package manager consistently within projects to avoid conflicts.

Package installation failures may result from network timeouts or corrupted cache. Clear Yarn’s cache and retry:

yarn cache clean
yarn install --network-timeout 100000

Performance Issues

Slow installation speeds can be improved by adjusting network settings:

yarn config set network-timeout 600000
yarn config set registry https://registry.npmjs.org/

Cache-related problems consume excessive disk space or cause installation failures. Monitor cache size and clean periodically:

yarn cache dir
du -sh $(yarn cache dir)
yarn cache clean

Updating and Maintaining Yarn

Updating Yarn to Latest Version

Update procedures vary depending on your installation method. For RPM installations, use DNF:

sudo dnf update yarn

NPM-based installations require:

sudo npm update -g yarn

Script-based installations need re-execution of the installation script:

curl -o- -L https://yarnpkg.com/install.sh | bash

Check for available updates:

yarn --version
npm view yarn version

Maintenance Best Practices

Regular cache cleanup prevents excessive disk usage:

yarn cache clean

Security update procedures should be part of your regular maintenance routine:

yarn audit
yarn upgrade

Backup strategies for projects include committing yarn.lock files to version control and documenting dependency management procedures for team members.

Monitor deprecated packages and plan migrations to maintained alternatives:

yarn outdated

Security Considerations

Package Security

Yarn audit functionality provides comprehensive security scanning:

yarn audit --summary
yarn audit --json

Address vulnerabilities through targeted upgrades or by finding secure alternatives. Never ignore security warnings in production environments.

Vulnerability scanning should be integrated into your development workflow. Configure automated audits in CI/CD pipelines to catch security issues early.

System Security

User permissions should follow the principle of least privilege. Avoid running Yarn with unnecessary elevated privileges and use sudo only when required for system-wide operations.

Network security considerations include verifying package sources and using corporate registries when available. Configure firewalls to allow necessary package manager traffic while blocking unauthorized connections.

Regular security updates for both Yarn and the underlying system ensure protection against emerging threats. Establish update schedules and monitor security advisories from relevant vendors.

Uninstalling Yarn

Complete Yarn removal varies by installation method. For RPM installations:

sudo dnf remove yarn

NPM-based installations require:

sudo npm uninstall -g yarn

Script-based installations need manual removal:

rm -rf ~/.yarn

Clean up configuration files and cache directories:

rm -rf ~/.cache/yarn
rm -f ~/.yarnrc

Remove repository configuration for RPM installations:

sudo rm /etc/yum.repos.d/yarn.repo

Verify complete removal by checking that Yarn commands are no longer available:

which yarn
yarn --version

Congratulations! You have successfully installed Yarn. Thanks for using this tutorial for installing Yarn Package Manager on your AlmaLinux OS 10 system. 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 an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button