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
Key Facts
- pnpm install installs dependencies listed in `package.json`.
- pnpm uses a shared, content-addressable store for disk space efficiency.
- The default location for the global store is `~/.pnpm-store`.
- A typical `pnpm install` operation takes less than a second for most projects.
- pnpm can also install specific packages by running `pnpm add <package_name>`.
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`
- Install pnpm: If you haven't already, you need to install pnpm globally. You can do this using npm:
npm install -g pnpmor by using other methods like Homebrew or its standalone installer. - Navigate to Your Project: Open your terminal or command prompt and use the
cdcommand to navigate to the root directory of your project. This is the directory that contains your `package.json` file. - 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:
- Deleting your `node_modules` folder and `pnpm-lock.yaml` file and running `pnpm install` again.
- Checking your pnpm version:
pnpm --version. Update if necessary. - Ensuring your `package.json` is correctly formatted.
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.
More How To in Daily Life
Also in Daily Life
More "How To" Questions
Trending on WhatAnswers
Browse by Topic
Browse by Question Type
Sources
- pnpm - InstallationCC-BY-4.0
- pnpm - Comparison with npmCC-BY-4.0
Missing an answer?
Suggest a question and we'll generate an answer for it.