1.10 macOS 与 Linux 双线生存指南
预计阅读时间:15 分钟
📖 目录
开发者常在 macOS(日常开发)和 Linux(服务器/生产环境)之间切换。两者的包管理器、路径、系统服务、默认工具差异显著。本文汇总差异与兼容方案,让你在双系统间无缝切换。
学习目标
学完本章,你将能够:
- 掌握 macOS(Homebrew)与 Linux(apt / dnf)包管理器的对应操作与跨平台切换方法
- 掌握 BSD 与 GNU 工具集的命令差异(sed、ls、stat 等)及兼容写法
- 理解 macOS 默认大小写不敏感与 Linux 大小写敏感对 Git 与文件系统的影响
- 掌握在 Linux 上使用 Homebrew(Linuxbrew)统一跨平台工具版本的方法
- 理解两个系统在路径、服务管理、网络配置上的差异
- 掌握 dotfiles 与 VS Code Remote SSH 实现跨平台环境一致性的最佳实践
前置知识
- 1.1:Linux 是什么 Linux 是什么——Linux 与 Unix 血缘、开源生态基础
- 1.3:第一次进入命令行 第一次进入命令行——终端、shell 与基础命令操作
- 2.11:SSH 深入 SSH 深入——SSH 密钥认证与远程文件传输
- 2.9:Git 版本控制 Git 版本控制——分支、合并与远程协作
包管理器差异
| macOS | Ubuntu/Debian | RHEL/Fedora | |
|---|---|---|---|
| 包管理器 | Homebrew | apt | dnf / yum |
| 安装包 | brew install | sudo apt install | sudo dnf install |
| 更新索引 | brew update | sudo apt update | sudo dnf check-update |
| 卸载 | brew uninstall | sudo apt remove | sudo dnf remove |
| 搜索 | brew search | apt search | dnf search |
| 清理 | brew cleanup | sudo apt autoremove | sudo dnf clean all |
# macOS 安装 Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Linux 上等价操作
sudo apt update && sudo apt upgrade -y # Ubuntu
sudo dnf update -y # Fedora
包管理器深度对比
| 特性 | Homebrew | apt | dnf |
|---|---|---|---|
| 依赖解析 | 自动,基于 formula | 自动,基于 .deb | 自动,基于 RPM |
| 配置文件 | /opt/homebrew/etc/ | /etc/apt/ | /etc/dnf/ |
| 源管理 | tap(第三方仓库) | sources.list | dnf.conf + .repo |
| 降级版本 | brew install foo@1.0 | apt install foo=1.0 | dnf downgrade foo |
| 查看依赖树 | brew deps | apt depends | dnf repoquery --requires |
| 手动安装 .deb | 不支持 | sudo dpkg -i pkg.deb | 不支持(用 rpm -i) |
| 搜索已安装 | brew list | dpkg -l | grep | rpm -qa | grep |
| 查看文件归属 | brew list --formula | dpkg -S /path | rpm -qf /path |
包管理器选择策略
| 工具类型 | 推荐包管理器 | 原因 |
|---|---|---|
| 开发语言运行时 | Homebrew | 版本更新快,支持多版本共存 |
| 系统级服务 | apt / dnf | 与 systemd 集成,开机自启配置方便 |
| 桌面应用 | Homebrew Cask / apt | macOS 用 Cask 管理 .app,Linux 用 apt 装 deb |
| C/C++ 库 | apt / dnf | 系统包管理器的 -dev 包包含头文件 |
| 跨平台 CLI 工具 | Homebrew | macOS 和 Linux 行为一致 |
核心命令对照
| 功能 | macOS | Linux |
|---|---|---|
| 查看进程 | ps aux | ps aux(相同) |
| 查看端口 | lsof -i :80 | ss -tlnp | grep 80 |
| 防火墙 | pfctl / socketfilterfw | ufw / nftables |
| 服务管理 | brew services / launchctl | systemctl |
| 磁盘分区 | Disk Utility / diskutil | fdisk / parted |
| 文件系统 | APFS(默认) | ext4 / xfs |
| DNS 配置 | /etc/resolv.conf(不可直接改) | /etc/resolv.conf |
| 网络配置 | System Preferences | nmcli / /etc/netplan/ |
BSD vs GNU 工具差异详解
| 命令 | macOS (BSD) | Linux (GNU) |
|---|---|---|
| 就地编辑 | sed -i '' 's/foo/bar/' | sed -i 's/foo/bar/' |
| 列出文件 | ls -G | ls --color=auto |
| 查看内存 | vm_stat | free -h |
| 网络接口 | ifconfig | ip addr |
| 查看磁盘 | df -h | df -h(相同) |
| 查看路由 | netstat -rn | ip route |
| 时间戳 | stat -f "%Sm" file | stat -c "%y" file |
| 读取文件 | cat -n file | cat -n file(相同) |
Homebrew 在 Linux 上的使用
Homebrew 也支持 Linux(Linuxbrew),可以在 Linux 上统一包管理:
# Linux 上安装 Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
# 好处:跨平台一致的工具版本(node、python、go)
brew install node python go ripgrep fd bat
统一开发环境 用 Homebrew 安装跨平台开发工具(node/python/go/ripgrep/bat),保证 macOS 和 Linux 上的工具版本一致,减少「我本地能跑」问题。
Shell 环境差异
macOS 默认 Shell
# macOS Ventura+ 默认 zsh
# ~/.zshrc 配置
# Homebrew 路径(Apple Silicon)
eval "$(/opt/homebrew/bin/brew shellenv)"
# 兼容 Linux 的 GNU 工具
export PATH="/opt/homebrew/opt/gnu-sed/libexec/gnubin:$PATH"
export PATH="/opt/homebrew/opt/gnu-coreutils/libexec/gnubin:$PATH"
Linux 默认 Shell
# Ubuntu 22.04+ 默认 bash
# ~/.bashrc 配置
# 简洁提示符
PS1='\[\e[32m\]\u@\h\[\e[0m\]:\[\e[34m\]\w\[\e[0m\]\$ '
跨平台 .bashrc / .zshrc
# 条件判断当前系统
if [[ "$(uname)" == "Darwin" ]]; then
# macOS 专用
alias ls='ls -G'
export LSCOLORS=GxFxCxDxBxegedabagaced
elif [[ "$(uname)" == "Linux" ]]; then
# Linux 专用
alias ls='ls --color=auto'
export LS_COLORS='di=34:ln=36:...'
fi
# 通用别名
alias ll='ls -la'
alias gs='git status'
alias dc='docker compose'
alias k='kubectl'
Shell 配置文件同步(Dotfiles 管理)
在 macOS 和 Linux 之间保持 Shell 配置一致,推荐使用 dotfiles 仓库 + 符号链接方案:
# 1. 创建 dotfiles 仓库
mkdir ~/dotfiles && cd ~/dotfiles
git init
# 2. 将配置文件移入仓库
mv ~/.bashrc .bashrc
mv ~/.zshrc .zshrc
mv ~/.gitconfig .gitconfig
mv ~/.tmux.conf .tmux.conf
# 3. 创建符号链接(macOS 和 Linux 通用)
ln -sf ~/dotfiles/.bashrc ~/.bashrc
ln -sf ~/dotfiles/.zshrc ~/.zshrc
ln -sf ~/dotfiles/.gitconfig ~/.gitconfig
ln -sf ~/dotfiles/.tmux.conf ~/.tmux.conf
# 4. 写一个自动安装脚本 install.sh
#!/bin/bash
DOTFILES_DIR="$HOME/dotfiles"
for file in .bashrc .zshrc .gitconfig .tmux.conf; do
ln -sf "$DOTFILES_DIR/$file" "$HOME/$file"
done
echo "Dotfiles 已安装"
推荐工具 可以使用
stow(GNU Stow)来管理符号链接,比手动 ln 更优雅:stow bash zsh git tmux 会自动创建指向 ~/dotfiles/ 下对应目录的符号链接。# 使用 stow 管理 dotfiles
sudo apt install stow # Linux
brew install stow # macOS
# 目录结构
~/dotfiles/
├── bash/
│ └── .bashrc
├── zsh/
│ └── .zshrc
├── git/
│ └── .gitconfig
└── tmux/
└── .tmux.conf
# 一键部署所有配置
cd ~/dotfiles && stow bash zsh git tmux
# 移除配置(取消符号链接)
cd ~/dotfiles && stow -D bash zsh git tmux
文件系统大小写敏感问题
问题详解
| 场景 | macOS (APFS 默认) | Linux (ext4) |
|---|---|---|
README.md vs readme.md | 同一文件 | 两个不同文件 |
| Git 操作 | core.ignorecase=true | core.ignorecase=false |
| 导入语句 | import './MyFile' 能找到 ./myfile.js | 报错 MODULE_NOT_FOUND |
| 文件名大小写重命名 | git mv File file 无效 | 正常重命名 |
解决方案
# 方案 1:创建大小写敏感的 APFS 卷(推荐)
diskutil apfs addVolume disk1 "Case-sensitive APFS" DevDisk
# 方案 2:在 Git 中强制区分大小写
git config core.ignorecase false
# 方案 3:在 macOS 上开发时,统一文件名命名规范
# 使用小写 + 连字符:my-component.js
# 避免使用:MyComponent.js、myComponent.js、mycomponent.js 混用
# 方案 4:在 package.json 中添加跨平台检查脚本
{
"scripts": {
"preinstall": "node -e \"const f=require('fs');const p=require('path');const dir='./src';const files=f.readdirSync(dir);const lower=files.map(f=>f.toLowerCase());if(new Set(lower).size!==lower.length){console.error('ERROR: 文件名大小写冲突');process.exit(1)}\""
}
}
大小写敏感 macOS 默认文件系统不区分大小写(Case-insensitive),Linux 默认区分。在 macOS 上开发时注意:
README.md 和 readme.md 是同一个文件,但在 Linux 上是两个不同文件。务必在项目初期统一命名规范,避免后期在 Linux 上出现大量导入错误。网络配置差异
| 功能 | macOS | Linux |
|---|---|---|
| 查看 IP | ifconfig en0 | ip addr show |
| 设置静态 IP | System Preferences → 网络 | /etc/netplan/01-config.yaml |
| DNS 配置 | System Preferences → DNS | /etc/resolv.conf 或 nmcli |
| 切换 DNS | scutil --dns | nmcli con mod eth0 ipv4.dns "8.8.8.8 8.8.4.4" |
| 查看路由 | netstat -rn | ip route show |
| 端口转发 | pfctl(需配置 pf.conf) | iptables -t nat -A PREROUTING |
| Wi-Fi 管理 | networksetup | nmcli device wifi |
# macOS 网络配置
# 查看所有网络接口
ifconfig -a
# 设置 DNS
sudo networksetup -setdnsservers Wi-Fi 8.8.8.8 8.8.4.4
# Linux 网络配置(netplan)
# /etc/netplan/01-config.yaml
network:
version: 2
ethernets:
eth0:
addresses:
- 192.168.1.100/24
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
# 应用 netplan 配置
sudo netplan apply
远程开发工具
VS Code Remote SSH 完整配置指南
# 步骤 1:macOS 本地安装 VS Code
# 从 https://code.visualstudio.com 下载安装
# 步骤 2:安装 Remote - SSH 扩展
code --install-extension ms-vscode-remote.remote-ssh
# 步骤 3:配置 SSH 密钥
ssh-keygen -t ed25519 -C "your-email@example.com"
ssh-copy-id user@linux-server
# 步骤 4:编辑 SSH 配置文件 ~/.ssh/config
Host my-linux-server
HostName 192.168.1.100
User ubuntu
IdentityFile ~/.ssh/id_ed25519
ForwardAgent yes
ServerAliveInterval 60
ServerAliveCountMax 3
# 步骤 5:在远程服务器安装 VS Code Server
# 首次连接时 VS Code 会自动安装
# 步骤 6:连接远程服务器
# 在 VS Code 中按 F1 → Remote-SSH: Connect to Host → 选择 my-linux-server
# 步骤 7:在远程工作区配置
# 可以在远程打开文件夹、安装扩展、运行终端
# 所有操作都在远程服务器上执行
VS Code Remote 常用配置
# ~/.ssh/config 中的高级配置
Host linux-server
HostName 192.168.1.100
User ubuntu
IdentityFile ~/.ssh/id_ed25519
ForwardAgent yes
ForwardX11 yes # 转发 X11 图形(用于 GUI 程序)
RequestTTY yes # 为 VS Code 终端分配 TTY
RemoteCommand bash -l # 登录 shell(加载 .bashrc)
ServerAliveInterval 60
ServerAliveCountMax 3
# VS Code settings.json 中的 Remote 配置
{
"remote.SSH.remotePlatform": {
"linux-server": "linux"
},
"remote.SSH.connectTimeout": 30,
"remote.SSH.showLoginTerminal": true
}
# tmux 在两个系统上保持一致的终端会话
# macOS 安装
brew install tmux
# Linux 安装
sudo apt install tmux
# 同步 tmux 配置
scp ~/.tmux.conf server:~/.tmux.conf
开发环境同步 Checklist
| 维度 | macOS 配置 | Linux 对应 |
|---|---|---|
| 编辑器 | VS Code + Remote SSH | VS Code Server |
| 终端 | iTerm2 + tmux | tmux |
| Git | ~/.gitconfig(全局共享) | ~/.gitconfig |
| SSH | ~/.ssh/config | ~/.ssh/config |
| Shell 配置 | ~/.zshrc | ~/.bashrc 或 ~/.zshrc |
| 工具版本 | Homebrew 安装 | Homebrew/Linux 或 apt |
开发环境一致性验证
# 验证两个系统的工具版本是否一致
echo "Node: $(node -v) | npm: $(npm -v)"
echo "Python: $(python3 --version)"
echo "Go: $(go version)"
echo "Git: $(git --version)"
# 检查关键工具路径
which node python3 go git docker
# 对比 .tool-versions(asdf 版本管理)
cat .tool-versions
# nodejs 20.11.0
# python 3.12.2
# golang 1.22.1
使用 asdf 统一版本管理 asdf 是一个跨语言的版本管理器,支持 Node.js、Python、Go、Ruby 等。在 macOS 和 Linux 上安装 asdf 后,通过
.tool-versions 文件统一指定每个工具的版本,确保两个系统使用完全相同的版本。路径与文件系统差异
| 功能 | macOS | Linux |
|---|---|---|
| 用户 home | /Users/username | /home/username |
| 系统配置 | /etc(部分在 /Library) | /etc |
| 临时文件 | /tmp → /private/tmp | /tmp |
| 挂载点 | /Volumes/ | /mnt/、/media/ |
| 大小写敏感 | 默认不敏感 | 默认敏感 |
| 二进制目录 | /usr/local/bin | /usr/bin |
| 日志目录 | /var/log + Console.app | /var/log |
| 内核参数 | sysctl(/etc/sysctl.conf) | sysctl(/etc/sysctl.d/) |
常见错误
- macOS 上
brew install报错Permission denied:Homebrew 目录权限问题。执行sudo chown -R $(whoami) /opt/homebrew(Apple Silicon)或/usr/local/Homebrew(Intel),不要用sudo brew。 - SSH 连接 Linux 服务器报
Connection refused:确认服务器已安装并启动 sshd,检查防火墙是否放行 22 端口:sudo ufw allow 22(Ubuntu)或sudo firewall-cmd --add-service=ssh(Fedora)。 - Linux 上
ls输出颜色混乱:macOS 的ls -G和 Linux 的ls --color=auto参数不同。在 .bashrc 中用uname判断系统后设置对应别名,确保跨平台兼容。 - 文件名大小写导致 Git 操作失败:macOS 默认不区分大小写,Git 也默认
core.ignorecase=true。在 Linux 上大小写敏感的文件(如README.mdvsreadme.md)会被 Git 视为不同文件,导致合并冲突。开发时应严格统一文件名大小写。 - Homebrew 在 Linux 上找不到安装的包:Linuxbrew 安装路径为
/home/linuxbrew/.linuxbrew,需要手动将eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"加入 shell 配置文件,否则命令不会出现在 PATH 中。 sed -i在 macOS 上报错:BSD sed 和 GNU sed 语法不同。macOS:sed -i '' 's/foo/bar/',Linux:sed -i 's/foo/bar/'。跨平台脚本中使用perl -pi -e 's/foo/bar/'作为替代方案,两者行为一致。- Git 克隆后文件权限异常:Linux 文件权限(chmod 755)会在 Git 中保留。在 macOS 上克隆含可执行权限的文件可能丢失权限位。使用
git config core.fileMode true保留权限。
最佳实践
- 用 dotfiles 管理跨平台配置:将 .bashrc/.zshrc/.gitconfig/.tmux.conf 等配置文件纳入 Git 版本管理,通过 symlink 或脚本在 macOS 和 Linux 上统一部署,保证环境一致性。
- 优先使用 Homebrew 安装开发工具:Homebrew 在 macOS 和 Linux 上提供一致的包名和版本,特别适合 node、python、go 等跨平台工具,避免因系统包管理器版本差异导致的兼容问题。
- VS Code Remote SSH 统一开发体验:在 macOS 本地使用 VS Code,通过 Remote SSH 连接 Linux 服务器编辑代码。终端、调试、扩展全部在远程执行,避免本地环境与服务器不一致。
- tmux 配置同步:macOS 和 Linux 上的 tmux 配置应保持一致。用
scp或 dotfiles 仓库同步.tmux.conf,确保快捷键、状态栏、窗口管理行为相同。 - 测试时覆盖两个平台:发布脚本或工具前,在 macOS 和 Linux 上分别运行测试。重点关注路径差异(
/tmpvs/private/tmp)、命令行为差异(sed -i在 BSD 和 GNU 上语法不同)和权限模型差异。
常见错误排查案例
现象:macOS 上的 shell 脚本在 Linux 上执行报 /bin/bash^M: bad interpreter。
排查:使用 file script.sh 查看文件编码,输出 ASCII text, with CRLF line terminators 表示行尾被转为 Windows 格式(\r\n)。
根因:macOS 上用非 Unix 编辑器编辑文件,或 Git 设置 core.autocrlf=true 自动转换行尾。
修复:在 .gitattributes 中添加 *.sh text eol=lf,或使用 dos2unix script.sh 批量转换行尾。
# 跨平台编码兼容脚本
#!/bin/bash
# fix_line_endings.sh — 自动修复 CRLF 为 LF
find . -name "*.sh" -o -name "*.py" -o -name "*.rb" | while read f; do
if file "$f" | grep -q "CRLF"; then
echo "Fixing: $f"
sed -i.bak 's/\r$//' "$f" && rm -f "$f.bak"
fi
done
macOS 与 Linux 的 SSH 配置差异
| 配置项 | macOS | Linux |
|---|---|---|
| SSH 服务 | 系统偏好设置 → 共享 → 远程登录 | sudo systemctl enable --now sshd |
| 配置文件 | /etc/ssh/sshd_config | /etc/ssh/sshd_config |
| 密钥目录 | ~/.ssh/ | ~/.ssh/ |
| 防火墙 | 系统偏好设置 → 安全性 | sudo ufw allow ssh |
| 默认端口 | 22 | 22 |
# macOS 上的 SSH 等价配置
# 启用 SSH
sudo systemsetup -setremotelogin on
# 查看 SSH 状态
sudo systemsetup -getremotelogin
# 生成 Ed25519 密钥(macOS 7.0+ 与 Linux 通用)
ssh-keygen -t ed25519 -C "your-email@example.com"
# 测试连通性
ssh -o ConnectTimeout=5 user@linux-server 'echo OK'
Homebrew 与 apt 常用包对应表
| 包名 | macOS (Homebrew) | Ubuntu (apt) |
|---|---|---|
| Python 3 | brew install python@3.12 | sudo apt install python3.12 |
| Node.js | brew install node@20 | curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - |
| Go | brew install go | sudo snap install go --classic |
| ripgrep | brew install ripgrep | sudo apt install ripgrep |
| fd | brew install fd | sudo apt install fd-find |
| bat | brew install bat | sudo apt install bat |
| fzf | brew install fzf | git clone --depth 1 https://github.com/junegunn/fzf ~/.fzf && ~/.fzf/install |
| jq | brew install jq | sudo apt install jq |
| tmux | brew install tmux | sudo apt install tmux |
| git | brew install git | sudo apt install git |
版本管理技巧 Homebrew 支持多版本共存(如
python@3.10 和 python@3.12),通过 brew link --overwrite 切换默认版本。Ubuntu 的 apt 通常只支持一个主版本,多版本需要通过 deadsnakes PPA 或 pyenv 实现。macOS 与 Linux 服务管理差异
| 操作 | macOS (launchd) | Linux (systemd) |
|---|---|---|
| 启动服务 | brew services start nginx | sudo systemctl start nginx |
| 停止服务 | brew services stop nginx | sudo systemctl stop nginx |
| 查看状态 | brew services list | systemctl status nginx |
| 开机自启 | brew services start nginx | sudo systemctl enable nginx |
| 查看日志 | log show --predicate 'process == "nginx"' | journalctl -u nginx -f |
| 手动加载 plist | launchctl load ~/Library/LaunchAgents/com.nginx.plist | sudo systemctl daemon-reload |
练习题
- 编写一个 shell 脚本,自动检测当前系统是 macOS 还是 Linux,然后安装对应的开发工具(macOS 用 Homebrew,Ubuntu 用 apt),并配置统一的 Git 用户信息(用户名和邮箱),写出脚本代码。
- 配置 VS Code Remote SSH 连接远程 Linux 服务器,要求:SSH 使用密钥认证、在远程服务器上安装 Go 并配置开发环境、在本地 VS Code 中远程调试一个 Go 程序。写出完整配置步骤和遇到的问题。
- 对比 macOS 和 Linux 上
sed -i命令的语法差异,编写一个兼容两个平台的文本替换函数(如将配置文件中的debug=false改为debug=true),并解释差异原因。 - 编写一个跨平台的自动化环境配置脚本,实现:自动检测操作系统、安装对应包管理器、安装指定工具列表(git、node、python3、docker)、配置 Git 别名和 Shell 别名。脚本需要处理每个步骤的错误情况并给出友好的提示信息。
本章总结
macOS 与 Linux 同源 Unix,差异集中在包管理器、BSD/GNU 命令语法与路径规范三处。用 Homebrew 统一跨平台工具链、以 dotfiles 管理配置、借助 VS Code Remote SSH 在远端编码,即可在两套系统间无缝切换。跨平台脚本务必先验证 sed、ls 等命令的行为差异。
延伸阅读
- 1.1:Linux 是什么 Linux 是什么——Linux 基础认知与发行版生态
- 1.3:第一次进入命令行 第一次进入命令行——终端基础与 Shell 概念
- 2.11:SSH 深入 SSH 深入——SSH 密钥认证与远程文件传输
- 2.9:Git 版本控制 Git 版本控制基础——分支、合并与远程协作
跨平台工具版本管理最佳实践
# 使用 asdf 统一管理跨平台工具版本
# 安装 asdf(macOS 和 Linux 通用)
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.14.0
echo '. "$HOME/.asdf/asdf.sh"' >> ~/.bashrc # 或 ~/.zshrc
# 安装插件
asdf plugin add nodejs
asdf plugin add python
asdf plugin add golang
# 安装指定版本
asdf install nodejs 20.11.0
asdf install python 3.12.2
asdf install golang 1.22.1
# 设置全局默认版本
asdf global nodejs 20.11.0
asdf global python 3.12.2
asdf global golang 1.22.1
# 项目级版本(在项目根目录创建 .tool-versions)
echo "nodejs 20.11.0" > .tool-versions
echo "python 3.12.2" >> .tool-versions
asdf 优势 asdf 是一个通用版本管理器,支持 500+ 种语言和工具。通过
.tool-versions 文件在项目级别锁定版本,确保团队成员使用完全相同的工具版本,消除「我本地能跑」问题。macOS 与 Linux 包管理器镜像加速
# macOS Homebrew 镜像加速(国内用户)
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"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
# Ubuntu apt 镜像加速
sudo sed -i 's|http://archive.ubuntu.com|https://mirrors.aliyun.com|g' /etc/apt/sources.list
sudo apt update
# Fedora dnf 镜像加速
sudo sed -i 's|metalink=|baseurl=https://mirrors.aliyun.com|g' /etc/yum.repos.d/*.repo
sudo dnf clean all && sudo dnf makecache
镜像选择 亚太地区用户建议使用清华 TUNA 或阿里云镜像,可显著提升包下载速度。镜像配置应纳入 dotfiles 仓库统一管理,确保所有开发机器使用相同的镜像源。
↑ 回到顶部