logo

亞太地區加速訪問教程

亞太地區網絡環境下,直接從官方源下載 Node.js 包、Git 以及通過 npm/Homebrew 安裝依賴時速度較慢甚至超時。本文介紹如何使用亞太地區鏡像源加速這些工具的安裝與使用。

安裝 Node.js

Windows

推薦使用清華大學鏡像站下載 Node.js 安裝包:

  1. 訪問 清華大學 Node.js 鏡像
  2. 下載 node-v24.0.0-x64.msi 安裝包
  3. 雙擊運行安裝,一路默認即可

或者直接訪問 Node.js 官網,選擇左側 LTS 版本下載。

安裝完成後打開命令行驗證:

node -v
npm -v

macOS

推薦使用 Homebrew 安裝(Homebrew 鏡像配置見下文):

brew install node

或使用 nvm 管理多版本:

curl -o- https://github.com/nvm-sh/nvm/raw/main/install.sh | bash
source ~/.zshrc
nvm install --lts

Linux

curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs

安裝 Git

Windows

推薦從清華大學鏡像站下載:

  1. 下載 Git-2.53.0.3-64-bit.exe(清華鏡像)
  2. 雙擊安裝,保持默認選項即可

安裝完成後驗證:

git --version

macOS

macOS 自帶 Git,也可通過 Homebrew 安裝最新版:

brew install git

Linux (Debian/Ubuntu)

sudo apt-get update
sudo apt-get install -y git

配置 npm 騰訊雲鏡像

npm 默認從 registry.npmjs.org 下載包,亞太地區訪問較慢。切換到騰訊雲鏡像可以顯著提升速度。

全局設置鏡像源

npm config set registry https://mirrors.cloud.tencent.com/npm/

驗證配置

npm config get registry

應顯示:https://mirrors.cloud.tencent.com/npm/

臨時使用(不修改全局配置)

在安裝命令後加 --registry 參數:

npm install -g @anthropic-ai/claude-code --registry https://mirrors.cloud.tencent.com/npm/

恢復官方源

npm config set registry https://registry.npmjs.org/

macOS Homebrew 鏡像加速

Homebrew 默認從 GitHub 拉取,亞太地區速度較慢。推薦使用清華大學鏡像源。

設置 Homebrew 鏡像

將以下內容追加到 ~/.zshrc

{
echo ''
echo '# Homebrew 清華鏡像'
echo 'export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"'
echo 'export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"'
echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"'
echo 'export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"'
echo 'export HOMEBREW_PIP_INDEX_URL="https://pypi.tuna.tsinghua.edu.cn/simple"'
} >> ~/.zshrc

使配置生效:

source ~/.zshrc

驗證

brew update

如果更新速度明顯加快,說明鏡像已生效。

首次安裝 Homebrew

如果尚未安裝 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_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
/bin/bash -c "$(curl -fsSL https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/install/raw/HEAD/install.sh)"

恢復官方源

unset HOMEBREW_API_DOMAIN
unset HOMEBREW_BOTTLE_DOMAIN
unset HOMEBREW_BREW_GIT_REMOTE
unset HOMEBREW_CORE_GIT_REMOTE
unset HOMEBREW_PIP_INDEX_URL
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew

pip 鏡像加速(可選)

如果使用 Python SDK,推薦配置 pip 騰訊雲鏡像:

pip config set global.index-url https://mirrors.cloud.tencent.com/pypi/simple

Git Clone 加速(可選)

對於 GitHub 上的倉庫,可以使用鏡像加速克隆:

# 使用 GitHub 代理
git clone https://gh.llkk.cc/https://github.com/用戶名/倉庫名.git

加速地址來自第三方 GitHub Proxy,請確認項目名和版本號一致。