简体   繁体   English

无法让 nvm 通过 shell 脚本更改节点版本

[英]Can't get nvm to change node version via shell script

I am working on two project, one which uses node 16 and one which uses node 18. I created a script in one of the projects to switch to 18 before running next dev.我正在处理两个项目,一个使用节点 16,一个使用节点 18。我在其中一个项目中创建了一个脚本,以便在运行下一个开发之前切换到 18。

Note: Nvm works in my terminal.注意:Nvm 在我的终端上工作。 I use zsh and installed nvm using homebrew.我使用 zsh 并使用自制软件安装了 nvm。

The scriptlooks like this:脚本看起来像这样:


# Change to correct node version
source $(brew --prefix nvm)/nvm.sh
nvm use 18

# Wait for the database to start
sleep 5

# Start dev with sudo 
sudo yarn next dev

However when I run the script with yarn I get: nvm is not compatible with the "PREFIX" environment variable: currently set to "/opt/homebrew" Run `unset PREFIX` to unset it.但是,当我使用 yarn 运行脚本时,我得到: nvm is not compatible with the "PREFIX" environment variable: currently set to "/opt/homebrew" Run `unset PREFIX` to unset it.

I have uninstalled node using brew, it does not help.我已经使用 brew 卸载了节点,但没有帮助。

Try installing nvm using the following script instead of using homebrew:尝试使用以下脚本而不是使用 homebrew 安装 nvm:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

And then close and reopen your terminal.然后关闭并重新打开您的终端。

If the problem still persists, you could refer to this answer here:如果问题仍然存在,您可以在这里参考这个答案:

https://stackoverflow.com/a/71282947/13007176 https://stackoverflow.com/a/71282947/13007176

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM