乐闻世界logo
搜索文章和话题

How to install pnpm without first installing npm

1个答案

1

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:

bash
npx 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:

bash
curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm

Using wget:

bash
wget -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.

2024年6月29日 12:07 回复

你的答案