step1:

    通过homebrew安装nvm

    brew install nvm
    注意:没有brew参照我的知乎文章:
    你新买的 MacBook air M1 所需的配置工作

    但是到这一步并没有安装好,这时直接使用nvm指令会得到:

    nvm zsh: command not found: nvm
    网上一些教程会告诉你要在 shell 文件(我是用的zsh,所以在~/.zshrc)中添加:

    export NVM_DIR=”NVM_DIR/nvm.sh” ] && . “NVM_DIR/bash_completion” ] && . “$NVM_DIR/bash_completion” # This loads nvm bash_completion
    ———————————————— 版权声明:本文为CSDN博主「曹天骄」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/solocao/article/details/83216819

    但添加后并没有用,还是显示command not found:nvm。原因是M1之后,homebrew不能放到 /usr/local/bin目录下了,要放到/opt目录下,所以以上指令要针对本地安装目录。

    step2:

    brew info nvm
    会根据你本机的配置情况得到相应的安装提示:

    You should create NVM’s working directory if it doesn’t exist:

    mkdir ~/.nvm

    Add the following to ~/.zshrc or your desired shell
    configuration file:

    export NVM_DIR=”$HOME/.nvm”
    [ -s “/opt/homebrew/opt/nvm/nvm.sh” ] && . “/opt/homebrew/opt/nvm/nvm.sh” # This loads nvm
    [ -s “/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm” ] && . “/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm” # This loads nvm bash_completion
    根据提示配置shell文件即可。

    https://www.cnblogs.com/xiaojunbo/p/15670193.html