• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

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

武飞扬头像
不是爱情的枪
帮助1

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了!

  1.  
    git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-cask
  2.  
    Homebrew/homebrew-cask
  3.  
     
  4.  
    git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-core
  5.  
    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)中添加如下内容:

  1.  
    # For NVM
  2.  
    export NVM_DIR=~/.nvm
  3.  
    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)"

学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgfkihj
系列文章
更多 icon
同类精品
更多 icon
继续加载