M1 Macpro 使用brew安装nvm切换不同版本node

1. 安装brew,回车根据提示选择镜像下载,文件较大下载中断请重试

/bin/zsh -c "$(curl -fsSL https://gitee.com/huwei1024/HomebrewCN/raw/master/Homebrew.sh)"

2. 安装完成后

 Warning: /opt/homebrew/bin is not in your PATH.
Instructions on how to configure your shell for Homebrew
can be found in the ‘Next steps’ section below.
==> Installation successful!

==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
Anonymous Aggregate User Behaviour Analytics — Homebrew Documentation
No analytics data has been sent yet (nor will any be during this install run).

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
GitHub - Homebrew/brew: 🍺 The missing package manager for macOS (or Linux)

==> Next steps:
– Run these two commands in your terminal to add Homebrew to your PATH:
echo ‘eval “$(/opt/homebrew/bin/brew shellenv)”‘ >> /Users/abel/.zprofile
eval “$(/opt/homebrew/bin/brew shellenv)”
– Run brew help to get started
– Further documentation:
https://docs.brew.sh

验证一下:

brew -v
Homebrew 3.6.1
Homebrew/homebrew-core (git revision a610f378f50; last commit 2022-09-17)

如果验证报错Command failed with exit 128:git

解决方式:

输入brew -v后会提示你执行两个配置命令,直接复制执行就ok了!

git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-cask
Homebrew/homebrew-cask

git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-core
Homebrew/homebrew-core

3. 安装nvm环境,如果已经安装过node看文章后续补充,需要删除node

brew reinstall nvm

终端报错: 

==> Downloading https://ghcr.io/v2/homebrew/core/nvm/manifests/0.39.1_1
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/nvm/blobs/sha256:6e14c8a2bf9421
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sh
######################################################################## 100.0%
==> Pouring nvm–0.39.1_1.all.bottle.tar.gz
==> Caveats
Please note that upstream has asked us to make explicit managing
nvm via Homebrew is unsupported by them and you should check any
problems against the standard nvm install method prior to reporting.

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” #
export M2_HOME=/usr/local/apache-maven-3.8.6
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

You can set $NVM_DIR to any location, but leaving it unchanged from
/opt/homebrew/opt/nvm will destroy any nvm-installed Node installations
upon upgrade/reinstall.

Type nvm help for further information.
==> Summary
🍺 /opt/homebrew/Cellar/nvm/0.39.1_1: 9 files, 184.1KB
==> Running brew cleanup nvm
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see man brew).

解决方法: 

安装完后配置环境变量

其次需要在shell的配置文件(~/.zshrc)中添加如下内容:

# For NVM
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh

注:如果此时使用命令ls -a查看文件夹目录没有.zshrc目录找不到,则需要:

解决方法:

第一步:vim .bash_profile

第二步:填入环境,保存退出,esc键+wq!

第三步:source .bash_profile     使环境变量生效

第四步:

        touch .zshrc

        open -e .zshrc
        source ~/.bash_profile

        然后command+s保存

第五步:source .zshrc     使环境变量生效

具体操作如下图:

 第三步:source .bash_profile

 

4. 注意:

1. 如果安装nvm之前已经安装了node,需要删除当前node版本

查找当前node安装路径命令:    which node

删除当前node:   rm -rf /Users/gia5gu/.nvm


2. ~/.bash_profile文件对应内容: eval "$(/opt/homebrew/bin/brew shellenv)"

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值