【macOS】mac M2 安装 Homebrew & nvm

gitee 快速安装

打开终端,复制如下命令,按回车执行(需要输入密码)

sh 复制代码
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

在这个过程中可能还会弹出安装 git 的提示,直接安装等待即可

然后再次输入上面的命令,输入1选择清华源就开始安装了

在本文发布之时,这个方法安装后会出现报错 -- ruby 版本过老

所以这个方法暂时不行,后面如果这个问题被解决了这个也是一个很省事的安装方法

官网安装

sh 复制代码
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

不过这个方法也会出现问题---无法连接 github (开了代理也会报错),后面我也就放弃了

中科院镜像安装

参考地址

首先,需要确保系统中安装了 bash、git 和 curl,对于 macOS 用户需额外要求安装 Command Line Tools (CLT) for Xcode。

在命令行输入 xcode-select --install 安装 CLT for Xcode 即可(自带有)。

接着,在终端输入以下几行命令设置环境变量:

sh 复制代码
export HOMEBREW_INSTALL_FROM_API=1
export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"

最后,在终端运行以下命令以安装 Homebrew

sh 复制代码
# 从本镜像下载安装脚本并安装 Homebrew / Linuxbrew
git clone --depth=1 https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/install.git brew-install
/bin/bash brew-install/install.sh

rm -rf brew-install

安装成功后需将 brew 程序的相关路径加入到环境变量中:

以下针对基于 Apple Silicon CPU 设备上的 macOS 系统(命令行运行 uname -m 应输出 arm64)上的 Homebrew:

sh 复制代码
test -r ~/.bash_profile && echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bash_profile
test -r ~/.zprofile && echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile

对基于 Intel CPU 设备上的 macOS 系统(命令行运行 uname -m 应输出 x86_64)的用户可跳过本步。

brew 安装 nvm

sh 复制代码
brew install 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

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

Type `nvm help` for further information.

Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> Summary
🍺  /usr/local/Cellar/nvm/0.35.3: 7 files, 150.0KB, built in 2 seconds

安装完成后根据其提示

sh 复制代码
# 创建 nvm 目录
mkdir ~/.nvm

# 编辑 ~/.zshrc 配置文件
vi ~/.zshrc

# 添加以下内容:
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

# 立即生效
source ~/.zshrc

# 检查是否配置成功
echo $NVM_DIR
# 出现下面内容就算成功了
/Users/your-username/.nvm
相关推荐
tedcloud1232 小时前
Wand-Enhancer:如何搭建一套远程开发与测试环境
前端·人工智能·macos·开源·流程图
A13345555 小时前
Windows/Mac/电脑播放器推荐:全平台怎么选
macos·电脑
云边有个稻草人5 小时前
飞牛 NAS 远程访问实战:星空组网连接 Mac 与安卓,从 Compose 部署到 5G 验证
android·5g·macos
for_ever_love__6 小时前
iOS: GCD高级API
macos·ios·objective-c·cocoa·多线程·gcd
深念Y8 小时前
黑苹果P400-卡顿排查与优化记录
linux·macos·ios·pve·黑苹果·英伟达·n卡
钱栈up1 天前
Mac端一键部署服务端项目:从流程梳理到踩坑适配的完整实践
macos
for_ever_love__1 天前
iOS: GCD进阶,全局队列与自定义队列
macos·ios·objective-c·cocoa·多线程·gcd
蓝丶曦月1 天前
Notion MacBook Apple M4 Pro 安装更新
macos·notion
我有满天星辰1 天前
【从 0 打造我的本地 AI 知识库】在 M1 Mac 上搭建 Ollama:我的本地 AI 模型到底应该怎么选?
人工智能·macos
我是Superman丶2 天前
Arduino IDE 安装教程:Windows/macOS/Linux 开发环境搭建
ide·windows·macos