How to Enable pnpm
pnpm
is an efficient package management tool. Compared to traditional npm
and yarn
, pnpm
manages dependencies through hard links and symlinks, significantly reducing disk space usage and improving installation speed. Using pnpm
can help developers manage project dependencies faster and enhance development efficiency.
Node.js installed via ServBay includes pnpm
by default. If you find that pnpm
is not enabled, you can enable it using the following steps.
Enable pnpm
Open the terminal and enter the following command to enable
pnpm
:bashcorepack enable pnpm
1If everything is correct, there will be no output from the above command.
To confirm that
pnpm
has been successfully enabled, enter the following command to check the version number:bashpnpm -v
1Example output:
bash9.1.0
1
Update pnpm
If you see the following prompt when you enter pnpm
, it means an updated version of pnpm
needs to be installed. Enter Y
to download and install:
$ pnpm -v
! Corepack is about to download https://registry.npmjs.org/pnpm/-/pnpm-9.0.6.tgz
? Do you want to continue? [Y/n]
9.0.6
2
3
4
5
Confirm the version number again:
$ pnpm -v
9.0.6
2
Specify a Version of pnpm to Run
If you need to specify a version of pnpm
to run, you can run it using the pnpm-<version>
format. For example:
pnpm-18 -v
Example output:
9.0.6
Benefits of Using pnpm
The main advantage of pnpm
lies in its efficient dependency management method, which significantly reduces disk space usage and improves installation speed through hard links and symlinks. Here are some practical examples of using pnpm
:
Install Dependencies
Install project dependencies using pnpm
:
pnpm install
This will install all dependencies listed in the package.json
file and create hard links and symlinks to optimize disk usage.
Add Dependency
Add a new dependency package:
pnpm add lodash
This will install the lodash
package and update the package.json
file.
Remove Dependency
Remove a dependency package:
pnpm remove lodash
This will remove the lodash
package from the project and update the package.json
file.
By using pnpm
, developers can enjoy faster dependency installation and reduced disk space usage, thereby enhancing overall development efficiency.