跳转到内容

macOS 命令速查

新机第一件事。官方安装脚本会自行处理 Command Line Tools 依赖。

终端窗口
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Apple Silicon 上 Homebrew 装在 /opt/homebrew,需要把它写进当前 shell 的环境:

终端窗口
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"

把已装的东西导出成清单,换机时一条命令还原,比逐个 brew install 可靠得多。

终端窗口
# Export what is currently installed
brew bundle dump --describe --force --file=~/Brewfile
# Restore on a new machine
brew bundle install --file=~/Brewfile
# Remove anything not listed in the Brewfile
brew bundle cleanup --force --file=~/Brewfile

默认用 ed25519,比 RSA 更短也更快。注释里写清楚这把钥匙属于哪台机器。

终端窗口
ssh-keygen -t ed25519 -C "laptop-$(date +%Y%m)" -f ~/.ssh/id_ed25519
# Load it into the agent and the macOS keychain
ssh-add --apple-use-keychain ~/.ssh/id_ed25519
# Copy the public key to the clipboard
pbcopy < ~/.ssh/id_ed25519.pub

启动开发服务器之前先确认端口是空的。

终端窗口
# Who is listening on port 4321
lsof -nP -iTCP:4321 -sTCP:LISTEN
# Kill it once you are sure
kill -15 <PID>
终端窗口
# Update formulae and upgrade everything
brew update && brew upgrade
# Reclaim disk space from old versions
brew cleanup --prune=all
# Check for problems before filing a bug
brew doctor