macOS (ARM64) 安装常用的开发软件

这个过程还是非常有意思的,尤其是网络连不通的那部分。

Xcode

整个过程都可以在 App Store 里完成,但安装完之后会影响到 git,在使用 git 的时候会看到一个消息

You have not agreed to the Xcode license agreements. You must agree to both license agreements below in order to use Xcode.

Hit the Return key to view the license agreements at '/Applications/Xcode.app/Contents/Resources/English.lproj/License.rtf'

回到桌面主页 同意就可以了。

homebrew

截止到 2021 年 4 月 国内的网络环境非常糟糕,GitHub会 timeout,这对于非常依赖 git 的 homebrew 来说 虽然安装非常困难,但是还是有优雅的办法的。
如果你的网络条件很好 直接一键安装即可,下面的步骤是手动安装。

homebrew 在 ARM 架构下的一个重大改动就是 所有的 ARM 架构软件都移动到了新的位置 /opt/homebrew/bin

mirrors

优化国内使用体验 主要是靠的 git repository 镜像。

  • 中科大 mirrors.ustc.edu.cn (推荐使用)
  • 清华 https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/ (好像挂掉了 不推荐)

fetch install.sh

  1. 打开 https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh
  2. 复制内容
  3. vim brew.sh
  4. command + v (粘贴内容)

替换 git remote

这里以中科大镜像为示例

打开 brew.sh

  1. HOMEBREW_BREW_DEFAULT_GIT_REMOTE (共1处)
HOMEBREW_BREW_DEFAULT_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"
  1. HOMEBREW_CORE_DEFAULT_GIT_REMOTE (共2处)
HOMEBREW_CORE_DEFAULT_GIT_REMOTE="https://mirrors.ustc.edu.cn/homebrew-core.git"

添加权限并执行

chmod +x brew.sh
./brew.sh

trouble shooting

Could not resolve HEAD to a revision

From https://mirrors.ustc.edu.cn/homebrew-core
 * [new branch]      master     -> origin/master
fatal: Could not resolve HEAD to a revision

可能有两种修复方式

  1. brew doctor

会告诉你修复的命令行

像是 git -C $(brew --repo homebrew/core) checkout master

  1. git reset

参考自 stackoverflow 的 Trying to install Hugo via Homebrew - “Could Not Resolve HEAD to a Revision”

use

git -C $(brew --repository homebrew/core) checkout master

or

git -C $(brew --repository homebrew/core) reset --hard HEAD.

NVM

通过 brew install nvm 安装

有几个注意的事项

NVM 路径

在安装完之后 会提示你 更新环境变量。
像是这样

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

注意 目录已经在 /opt/homebrew 下了

安装 node

尽量使用 nvm 提供的 lts 版本名称

例如

  • lts/erbium

安装过程中会编译 node,记得找个闲暇的下午来做这个事情。( M1 虽然编译速度快 但也是需要时间的)

默认使用的版本

安装完之后 每次都要用 nvm use 命令?

原因只是 因为 default 没有得到正确的指向

使用下面的命令来指向到 默认使用的 node 版本

nvm alias default lts/erbium