Even without directly using npm, there are several ways to install pnpm. Here are two common methods:
Method 1: Using npx
Although this method still depends on npm, you can execute it without explicitly installing npm. npx is part of npm 5.2.0 and later, allowing you to run packages without installing them. The key is that npx is often pre-installed in many environments, so you may not need additional installation steps.
You can run the following command to install pnpm:
bashnpx pnpm add -g pnpm
This command temporarily installs pnpm and uses it to globally install its stable version.
Method 2: Using an Independent Installation Script
If your environment has neither npm nor npx, consider using an independent installation script. pnpm provides a command-line tool that can be installed via a simple script. This method does not depend on npm.
You can use curl or wget to download and run this installation script:
Using curl:
bashcurl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm
Using wget:
bashwget -qO- https://get.pnpm.io/v6.16.js | node - add --global pnpm
These commands download the latest installation script and execute it via Node.js to install pnpm.
Conclusion
Both methods allow you to install pnpm without directly using npm. The first method is suitable for environments where npx is already pre-installed, while the second method works for any environment with Node.js, regardless of whether npm is installed. This provides flexibility, enabling you to install and use pnpm even in environments with strict restrictions.