SurferCloud Blog SurferCloud Blog
  • HOME
  • NEWS
    • Latest Events
    • Product Updates
    • Service announcement
  • TUTORIAL
  • COMPARISONS
  • INDUSTRY INFORMATION
  • Telegram Group
SurferCloud Blog SurferCloud Blog
SurferCloud Blog SurferCloud Blog
  • HOME
  • NEWS
    • Latest Events
    • Product Updates
    • Service announcement
  • TUTORIAL
  • COMPARISONS
  • INDUSTRY INFORMATION
  • Telegram Group
  • banner shape
  • banner shape
  • banner shape
  • banner shape
  • plus icon
  • plus icon

How to Install and Use PNPM on Linux?

December 13, 2024
4 minutes
TUTORIAL
1366 Views

PNPM (Performant NPM) is a fast, disk space-efficient package manager for Node.js. Compared to traditional NPM or Yarn, PNPM uses a clever strategy to store packages in a central content-addressable storage, resulting in faster installations and reduced disk space usage. If you’re looking for a lightweight, fast alternative to NPM, PNPM is a great choice.

This guide will walk you through the installation process and how to use PNPM on Linux.


What is PNPM?

PNPM is a package manager similar to NPM and Yarn, but with several key differences:

  • Faster Installations: It uses a single content-addressable storage for all packages, avoiding redundant downloads.
  • Less Disk Space Usage: Instead of duplicating files across multiple projects, PNPM creates hard links.
  • Better Monorepo Support: It offers superior support for monorepos, making it a popular choice for larger development teams.

Step 1: Update System Packages

Before installing PNPM, it's a good idea to update your system's package list to ensure all tools are up to date. Run the following commands:

sudo apt-get update
sudo apt-get upgrade -y

This updates the system repositories and upgrades existing packages.


Step 2: Install Node.js and NPM

PNPM requires Node.js to run. If you don’t have Node.js installed, you can install it using the NodeSource repository. Run the following commands to install the latest stable version of Node.js:

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs

Verify that Node.js and NPM are installed by running:

node -v
npm -v

You should see output similar to:

v18.17.0
8.11.0

This confirms that Node.js and NPM have been installed successfully.


Step 3: Install PNPM

There are several ways to install PNPM, but the simplest method is to use the following script:

curl -fsSL https://get.pnpm.io/install.sh | sh -

Note: This script will install PNPM in your user's home directory (~/.local/share/pnpm).

After the installation is complete, add PNPM to your system's PATH by adding the following line to your ~/.bashrc or ~/.zshrc file:

export PATH="$HOME/.local/share/pnpm:$PATH"

Apply the changes to your current session with:

source ~/.bashrc

To verify the installation, run:

pnpm -v

If the command returns a version number, PNPM has been installed successfully.


Step 4: Using PNPM Commands

PNPM works similarly to NPM, so you can use familiar commands to manage Node.js packages. Here are some key PNPM commands to get you started:

CommandDescription
pnpm initInitializes a new project (like npm init)
pnpm installInstalls all dependencies listed in package.json
pnpm install <pkg>Installs a specific package
pnpm add <pkg>Adds a package to dependencies
pnpm add -D <pkg>Adds a package to devDependencies
pnpm remove <pkg>Removes a specific package
pnpm updateUpdates all installed packages

Example 1: Install a specific package (like Express):

pnpm add express

Example 2: Install a package as a development dependency:

pnpm add -D eslint

Step 5: Using PNPM with Monorepos

One of PNPM's strengths is its support for monorepos. A monorepo allows multiple projects to exist within a single repository, and PNPM makes managing shared dependencies across these projects much easier.

To create a monorepo using PNPM, follow these steps:

  1. Create a New Directory for your monorepo: mkdir my-monorepo cd my-monorepo
  2. Create a pnpm-workspace.yaml file in the root directory: packages: - 'packages/*'
  3. Create Subdirectories for Projects: mkdir -p packages/project-a mkdir -p packages/project-b
  4. Initialize Each Sub-Project: cd packages/project-a pnpm init -y

Now you can manage all dependencies for the monorepo in one place.


Step 6: Keeping PNPM Up-to-Date

To update PNPM to the latest version, use the following command:

pnpm add -g pnpm

You can also check for updates with:

pnpm --version

This ensures that you’re using the latest version of PNPM with the newest features and performance improvements.


Why Use PNPM Instead of NPM or Yarn?

FeaturePNPMNPMYarn
Speed✅ Faster⚠️ Slower⚠️ Slower
Disk Usage✅ Lower⚠️ Higher⚠️ Higher
Monorepo Support✅ Best-in-class⚠️ Limited✅ Good
Offline Mode✅ Supported⚠️ Limited✅ Supported

Why Choose PNPM?

  • Speed: PNPM is faster due to its use of hard links instead of copying files.
  • Efficiency: Uses a single content store for packages, saving disk space.
  • Monorepos: PNPM is widely regarded as one of the best tools for managing monorepos.

Why Choose SurferCloud?

If you need a fast, reliable server for your Node.js, PNPM, or monorepo projects, SurferCloud is an excellent choice. SurferCloud offers high-performance, globally distributed servers with data centers in Asia, Europe, and the Americas. Whether you need a VPS to deploy your Node.js app or a development environment for monorepos, SurferCloud has you covered. With affordable pricing and 16 global server locations, you can enjoy fast performance and low latency wherever you are.

Tags : install PNPM Linux Linux PNPM tutorial Node.js PNPM guide PNPM Linux install PNPM monorepo PNPM vs NPM SurferCloud VPS for Node.js

Related Post

2 minutes TUTORIAL

How to Install Pip on Ubuntu?

Pip is an essential tool for managing Python packages, ...

5 minutes TUTORIAL

How to Enable the Active Directory Recycle Bi

Accidentally deleting users, groups, or organizational ...

3 minutes INDUSTRY INFORMATION

Enhancing Browsing Speed: How to Enable Ad Bl

As internet usage grows, many users seek ways to enhanc...

Affordable CDN

ucdn

2025 Special Offers:

annual vps

Light Server promotion:

ulhost-promo

Cloud Server promotion:

cloud server

Copyright © 2024 SurferCloud All Rights Reserved.  Sitemap.