How to pnpm install

Content on WhatAnswers is provided "as is" for informational purposes. While we strive for accuracy, we make no guarantees. Content is AI-assisted and should not be used as professional advice.

Last updated: April 4, 2026

Quick Answer: To install packages with pnpm, open your terminal or command prompt, navigate to your project directory, and run the command `pnpm install`. This will read your `package.json` file and install all necessary dependencies into your project's `node_modules` folder, utilizing pnpm's efficient content-addressable store.

Key Facts

What is pnpm?

pnpm (performant npm) is a package manager for Node.js, similar to npm and yarn. It aims to be fast, disk space-efficient, and strictly adhere to semantic versioning. Its core innovation lies in how it manages dependencies, using a content-addressable store and symlinks to avoid duplication and improve installation speed.

How does `pnpm install` work?

When you run `pnpm install` in your project directory, pnpm reads your `package.json` file. It identifies all the dependencies required by your project, including production dependencies, development dependencies, and optional dependencies.

Dependency Resolution and Installation

Unlike traditional package managers that might copy packages directly into your project's `node_modules` folder, pnpm uses a sophisticated approach. It maintains a central, global store on your disk (typically located at `~/.pnpm-store` by default). When a package is installed for the first time, pnpm downloads it into this global store. Subsequent installations of the same package version, whether in the same project or different projects on your machine, will simply create hard links or symlinks to the already downloaded package in the global store. This significantly reduces disk space usage, especially if you work on many projects that share common dependencies.

The `node_modules` Structure

The `node_modules` folder in your project is structured in a way that enforces non-flatness. This means that your project can only directly access its own dependencies, not the dependencies of its dependencies (transitive dependencies). This stricter structure helps prevent common issues related to phantom dependencies (accessing packages that are not explicitly listed in your `package.json`) and helps ensure that your project's dependencies are well-defined and managed.

Steps to Run `pnpm install`

  1. Install pnpm: If you haven't already, you need to install pnpm globally. You can do this using npm: npm install -g pnpm or by using other methods like Homebrew or its standalone installer.
  2. Navigate to Your Project: Open your terminal or command prompt and use the cd command to navigate to the root directory of your project. This is the directory that contains your `package.json` file.
  3. Run the Command: Type the following command and press Enter: pnpm install

pnpm will then read your `package.json`, resolve all dependencies, and install them into your project's `node_modules` folder, creating the necessary links to the global store.

Common Scenarios and Options

Installing Specific Packages

If you want to install a single package and add it to your `package.json`, you can use the pnpm add command:

pnpm add

To add a development dependency:

pnpm add -D

Updating Packages

To update all packages to their latest allowed versions according to your `package.json` (respecting semver ranges):

pnpm update

Uninstalling Packages

To remove a package and update your `package.json`:

pnpm remove

Troubleshooting

If you encounter issues, common solutions include:

pnpm's efficiency and strict dependency management make it a powerful tool for modern JavaScript development. By understanding how `pnpm install` works, you can leverage its benefits for faster and more reliable project setups.

Sources

  1. pnpm - InstallationCC-BY-4.0
  2. pnpm - Comparison with npmCC-BY-4.0

Missing an answer?

Suggest a question and we'll generate an answer for it.