China Mirrors — 中国镜像
v3自动配置 Python pip、npm、yarn、pnpm、cargo、go mod、NuGet、RubyGems、Conda、Homebrew、Gradle 等包管理器的国内镜像源。当用户提到下载慢、安装依赖、配置镜像、加速包下载、设置国内源,或在中国大陆开发需要加速依赖安装时使用。支持阿里云、腾讯云、清华大学、中科大、华为云等主流镜像。检测到 package.json、requirements.txt、Cargo.toml、go.mod、Gemfile、.nuspec、environment.yml 等文件时主动建议使用此技能。
运行时依赖
安装命令
点击复制技能文档
中国国内镜像源配置技能(Agent 自执行版) 核心设计理念:本技能不附带任何预置脚本。Agent 应根据本文档的指导,直接在用户计算机上编写并执行配置命令,实现镜像源配置功能。
工作流程(Agent 必须遵循) Phase 1: 需求检测与环境分析 当触发本技能时,Agent 按以下步骤操作: 1.1 触发条件识别 用户明确提及:下载慢、安装依赖慢、配置镜像、加速下载、设置国内源 检测到项目包含依赖文件:package.json、requirements.txt、Cargo.toml、go.mod、Gemfile、.nuspec、environment.yml、build.gradle、pom.xml、composer.json 1.2 与用户确认 询问内容:
- 需要配置哪些包管理器?(如未指定,根据项目依赖文件自动判断)
- 有偏好的镜像源吗?(默认推荐阿里云或华为云)
- 配置范围:全局配置 or 项目级配置?
Phase 2: 选择镜像源 根据下表为用户选择最优镜像。标记 ⭐ 的为当前推荐。 包管理器 推荐镜像 URL 备选1 备选2 pip (Python) 阿里云 ⭐ https://mirrors.aliyun.com/pypi/simple/ 清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/ 腾讯云 https://mirrors.cloud.tencent.com/pypi/simple/ npm/yarn/pnpm 华为云 ⭐ https://repo.huaweicloud.com/repository/npm/ 阿里云 https://registry.npmmirror.com 腾讯云 https://mirrors.cloud.tencent.com/npm/ cargo (Rust) 阿里云 ⭐ https://mirrors.aliyun.com/crates.io-index/ 清华大学 https://mirrors.tuna.tsinghua.edu.cn/crates.io-index/ 中科大 https://mirrors.ustc.edu.cn/crates.io-index/ go mod (Go) 阿里云 ⭐ https://mirrors.aliyun.com/goproxy/ 七牛云 https://goproxy.cn 官方中国 https://goproxy.io Maven (Java) 阿里云 ⭐ https://maven.aliyun.com/repository/public - - Gradle (Java/Kotlin) 腾讯云 ⭐ https://mirrors.cloud.tencent.com/gradle/ 阿里云 https://maven.aliyun.com/repository/gradle-plugin/ - NuGet (.NET) 华为云 ⭐ https://repo.huaweicloud.com/repository/nuget/v3/index.json 清华大学 https://mirrors.tuna.tsinghua.edu.cn/nuget/v3/index.json - RubyGems (Ruby) 清华大学 ⭐ https://mirrors.tuna.tsinghua.edu.cn/rubygems/ 中科大 https://mirrors.ustc.edu.cn/rubygems/ - Conda (Python) 清华大学 ⭐ https://mirrors.tuna.tsinghua.edu.cn/anaconda/ 中科大 https://mirrors.ustc.edu.cn/anaconda/ - Homebrew (macOS) 中科大 ⭐ https://mirrors.ustc.edu.cn/homebrew-bottles/ 清华大学 https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/ - Composer (PHP) 阿里云 ⭐ https://mirrors.aliyun.com/composer/ - -
Phase 3: 执行配置(Agent 直接运行命令) 重要:Agent 根据用户选择的包管理器和镜像,直接在终端执行以下对应命令。 不要创建临时脚本文件,直接使用原生命令或 Shell 命令完成配置。 3.1 Python pip 配置 Windows 全局配置: New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\pip" Set-Content -Path "$env:USERPROFILE\pip\pip.ini" -Value @" [global] index-url = https://mirrors.aliyun.com/pypi/simple/ trusted-host = mirrors.aliyun.com [install] trusted-host = mirrors.aliyun.com "@ -Encoding UTF8 Write-Host "✓ pip 已配置为阿里云镜像" Linux/Mac 全局配置: mkdir -p ~/.pip cat > ~/.pip/pip.conf << 'EOF' [global] index-url = https://mirrors.aliyun.com/pypi/simple/ trusted-host = mirrors.aliyun.com [install] trusted-host = mirrors.aliyun.com EOF echo "✓ pip 已配置为阿里云镜像" 项目级配置(在项目根目录): # 创建 .piprc 或 setup.cfg cat > pip.conf << 'EOF' [global] index-url = https://mirrors.aliyun.com/pypi/simple/ trusted-host = mirrors.aliyun.com EOF echo "✓ pip 项目级配置已完成" 验证: pip config list 3.2 Node.js npm/yarn/pnpm 配置 全局配置: # npm npm config set registry https://registry.npmmirror.com # yarn(如已安装) yarn config set registry https://registry.npmmirror.com 2>/dev/null || true # pnpm(如已安装) pnpm config set registry https://registry.npmmirror.com 2>/dev/null || true echo "✓ Node.js 包管理器已配置" 项目级配置(创建 .npmrc): echo "registry=https://registry.npmmirror.com" > .npmrc echo "✓ npm 项目级配置已完成" 验证: npm config get registry 3.3 Rust cargo 配置 全局配置: mkdir -p ~/.cargo cat > ~/.cargo/config.toml << 'EOF' [source.crates-io] replace-with = 'aliyun' [source.aliyun] registry = "https://mirrors.aliyun.com/crates.io-index/" EOF echo "✓ cargo 已配置为阿里云镜像" 验证: cat ~/.cargo/config.toml 3.4 Go mod 配置 Windows PowerShell: [Environment]::SetEnvironmentVariable("GOPROXY", "https://mirrors.aliyun.com/goproxy/,direct", "User") $env:GOPROXY = "https://mirrors.aliyun.com/goproxy/,direct" Write-Host "✓ Go GOPROXY 已配置" Linux/Mac: echo 'export GOPROXY=https://mirrors.aliyun.com/goproxy/,direct' >> ~/.bashrc export GOPROXY=https://mirrors.aliyun.com/goproxy/,direct echo "✓ Go GOPROXY 已配置" 验证: go env GOPROXY 3.5 NuGet (.NET) 配置 Windows: $nugetPath = "$env:APPDATA\NuGet" New-Item -ItemType Directory -Force -Path $nugetPath Set-Content -Path "$nugetPath\NuGet.Config" -Value @" "@ -Encoding UTF8 Write-Host "✓ NuGet 已配置为华为云镜像" Linux/Mac: mkdir -p ~/.nuget cat > ~/.nuget/NuGet.Config << 'EOF' EOF echo "✓ NuGet 已配置为华为云镜像" ...(剩余部分未提供)