17

I am work on monorepo stuff, and found that some guys use pnpm install to install packages in workspace, but some other use pnpm add.

in the pnpm docs, its seem like the same between add and install command, but there are some different options like --offline (for install)、--workspace(for add), and if I use pnpm install [pkg name] --workspace, its work normally.

so what the different between pnpm install and pnpm add?

3 Answers 3

24

There is not much difference between them. In most cases they are interchangeable:

pnpm install <args?>: without args it will scan and install all the modules listed in pnpm-lock.yaml, in case of args it works as pnpm add

pnpm add <args>: It will install one more package.

if choose yes i will use pnpm add because it is new modern syntax that supports all package managers (npm add, yarn add)

1
  • 6
    The only difference is that pnpm add will fail when executed without args. pnpm install will work in both cases. I recommend using pnpm add when you add new dependencies because the pnpm tab autocompletion will work better. Commented Aug 23, 2022 at 7:59
11

Basically as per their docs:


We need to use pnpm add when we want to add a new dependency to our project


We will be needing to use pnpm install when we have an existing project with the lockfile and we want to install all dependencies from the lockfile.


For more information please refer to the official docs:

PNPM Add Docs
PNPM Install Docs

6

pnpm add : Installs a package and any packages that it depends on.
pnpm install : is used to install all dependencies for a project.

https://pnpm.io/cli/install
https://pnpm.io/cli/add

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.