如何在PNPM版本之间切换?

发布于 2025-01-26 15:40:35 字数 69 浏览 5 评论 0 原文

我目前正在使用使用PNPM 6但已安装PNPM 7的应用程序。我找不到任何文档,向我展示了如何在版本之间安装和切换。谢谢你!

I'm currently working on an application that uses pnpm 6 but I have pnpm 7 installed. I couldn't find any documentation that shows me how to install and switch between versions. Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

执手闯天涯 2025-02-02 15:40:35

如果您已经通过node.js corepack

corepack enable

对于节点V18,则可以运行:

corepack prepare [email protected] --activate

这是 for node v18

for node v20+您可以运行:

corepack install --global [email protected]

这是 corepack docs for Node V20

If you have installed pnpm through Node.js corepack:

corepack enable

For Node v18 you can run:

corepack prepare [email protected] --activate

Here are the corepack docs for Node v18

For Node v20+ you can run:

corepack install --global [email protected]

Here are the corepack docs for Node v20

情定在深秋 2025-02-02 15:40:35

如果您希望使用想要的PNPM版本,请使用 npx

npx pnpm@<version> <command>

例如,我在全球安装了PNPM 8,但想为取决于PNPM 6的项目做出贡献。这是我怎么做:

npx pnpm@6 install

If you wish for a one-liner to use whichever pnpm version you want, use npx:

npx pnpm@<version> <command>

For example, I have pnpm 8 installed globally but want to contribute to a project that depends on pnpm 6. This is how I do it:

npx pnpm@6 install
情魔剑神 2025-02-02 15:40:35

我也可以使用 node.js/corepack 。对于不同的项目,我必须在6和7之间跳跃。

凭借最新版本的Node.js(16.17+),在PNPM的最新版本的最新版本之间更容易切换。对于最新版本7,您要键入:

corepack prepare pnpm@latest --activate

对于第6版的最新版本:

corepack prepare pnpm@latest-6 --activate

它也在 pnpm。

I'm also going with node.js/corepack. I have to jump between versions 6 and 7 for different projects.

With a recent version of node.js (16.17+) it's even easier to switch between the most recent of major versions of pnpm. For the latest of version 7 you'd type:

corepack prepare pnpm@latest --activate

For the latest of version 6:

corepack prepare pnpm@latest-6 --activate

It's also described in the installation doc of pnpm.

难以启齿的温柔 2025-02-02 15:40:35

可能有一个更好的方法,但我只是卸载了版本7并安装了6版。我使用纱线做到了这一点,但是您可以使用卸载/安装文档中列出的任何方法来完成此操作。只需确保使用最初用于安装它的方法卸载(NPM,纱,酿造等)即可。

这是我所做的:

yarn global remove pnpm
yarn global add [email protected] (installed specific latest pnpm version)

当前,似乎没有类似于NVM的解决方案。 参考

There may be a better way but I just uninstalled version 7 and installed version 6. I did this with yarn but you can do it with any method listed in the uninstall/install documentation. Just make sure you uninstall using the method you originally used to install it (npm, yarn, brew, etc.).

This is what I did:

yarn global remove pnpm
yarn global add [email protected] (installed specific latest pnpm version)

Currently, it seems there is no solution similar to nvm. Reference

梦罢 2025-02-02 15:40:35

In my case, to setup the nextauthjs local environment on Ubuntu 22.04 I did the followings.

俏︾媚 2025-02-02 15:40:35

您可以做到这一点,

// enable corepack
corepack enable
// switch pnpm 7 version
corepack prepare [email protected] --activate
// switch pnpm latest version
corepack prepare pnpm@latest --activate

您可以设置Bash别名

alias pnpm7='corepack prepare [email protected] --activate'
alias pnpmlatest='corepack prepare pnpm@latest --activate'

you can do it

// enable corepack
corepack enable
// switch pnpm 7 version
corepack prepare [email protected] --activate
// switch pnpm latest version
corepack prepare pnpm@latest --activate

you can set bash alias

alias pnpm7='corepack prepare [email protected] --activate'
alias pnpmlatest='corepack prepare pnpm@latest --activate'
倦话 2025-02-02 15:40:35

我在2022年或2023年在Windows上安装了PNPM。

我进行了全局安装,但是“ PNPM -V”总是返回旧版本:

PNPM I -G PNPM

pnpm i -g @pnpm/exe

pnpm ls -g

// @pnpm/exe 8.5.1

// PNPM 8.5.1

pnpm -v

// 7.25.1

“ PNPM -V”最终在运行以下命令之后给了我8.5.1:

corepack启用

corepack准备

I installed pnpm with Vite in 2022 or 2023 on Windows.

I did the global installations but 'pnpm -v' always returned the old version:

pnpm i -g pnpm

pnpm i -g @pnpm/exe

pnpm ls -g

// @pnpm/exe 8.5.1

// pnpm 8.5.1

pnpm -v

// 7.25.1

The 'pnpm -v' finally gave me 8.5.1 after running the following commands:

corepack enable

corepack prepare [email protected] --activate

梦里泪两行 2025-02-02 15:40:35

如果您正在使用Windows

$env:PNPM_VERSION="8.9.0"

iwr https://get.pnpm.io/install.ps1 -useb | iex

If you are using windows

$env:PNPM_VERSION="8.9.0"

iwr https://get.pnpm.io/install.ps1 -useb | iex
写给空气的情书 2025-02-02 15:40:35

如果您运行

corepack enable

则可以在project package.json中指定PNPM版本。

例如,

{
"name": "some project",
"packageManager": "[email protected]",
.....
}

在运行 PNPM安装或任何 pnpm 命令时,CorePack将下载并使用指定的PNPM版本,而无需任何其他安装。

当并非所有项目都使用相同的锁定格式时,这特别有用。

if you run

corepack enable

you can then specify the pnpm version in the project package.json.

e.g.

{
"name": "some project",
"packageManager": "[email protected]",
.....
}

when running pnpm install or any pnpm command, corepack will download and use the specified pnpm version without any further installation.

This is especially helpfull when not all projects are using the same lockfile format.

沫离伤花 2025-02-02 15:40:35
corepack enable pnpm
corepack use pnpm@<version>

更多详细信息:
https://pnpm.io/installation#using-corepack

corepack enable pnpm
corepack use pnpm@<version>

more details:
https://pnpm.io/installation#using-corepack

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文