简体   繁体   中英

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.

Note: Nvm works in my terminal. I use zsh and installed nvm using homebrew.

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.

I have uninstalled node using brew, it does not help.

Try installing nvm using the following script instead of using homebrew:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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