China Mirrors

Polar Sponsor
爱发电 赞助
.NET 9.0

自动为 Python pip、npm、yarn、pnpm、cargo、go mod、NuGet、RubyGems、Conda、Homebrew、Gradle 等包管理器配置国内镜像。适用于用户提及下载慢、安装依赖、配置镜像、加速包下载、设置国内源,或在中国大陆开发需加速依赖安装的场景。支持阿里云、腾讯云、清华大学等镜像。

中国国内镜像源配置技能(Agent 自执行版)

功能概述

中国国内镜像源配置技能(Agent 自执行版)是一项面向实际任务的技能,主要用于核心设计理念 :本技能不附带任何预置脚本;Agent 应根据本文档的指导, 直接在用户计算机上编写并执行配置命令 ,实现镜像源配置功能;

核心要点

  • 工作流程(Agent 必须遵循);
  • Phase 1: 需求检测与环境分析;
  • 当触发本技能时,Agent 按以下步骤操作:;

使用与执行

1.1 触发条件识别;用户明确提及:下载慢、安装依赖慢、配置镜像、加速下载、设置国内源。它将相关步骤、工具调用和结果整理方式集中到统一流程中,帮助使用者更快完成目标并减少重复操作。从功能定位来看,该技能强调把分散的操作要求整理成清晰、可复用的处理流程,使用户能够围绕既定目标快速准备输入、选择执行方式并获得结构化结果。

结果检查与注意事项

实际使用前应先确认任务范围、数据来源、运行环境、必要权限和关键参数,再依据技能说明逐步执行;若输入条件不完整,应先补齐信息或采用保守配置,避免因错误假设导致结果偏离需求。执行过程中需要关注工具调用是否成功、接口或依赖是否可用、输出格式是否符合预期,并对异常提示、缺失字段和边界情况进行处理;涉及批量任务时,还应保存进度,避免中断后重复操作。

中国国内镜像源配置技能(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 与用户确认

询问内容:
1. 需要配置哪些包管理器?(如未指定,根据项目依赖文件自动判断)
2. 有偏好的镜像源吗?(默认推荐阿里云或华为云)
3. 配置范围:全局配置 or 项目级配置?

1.3 环境检测命令 Agent 执行以下命令检测已安装的工具:

# Windows PowerShell 检测
python --version 2>$null; node --version 2>$null; npm --version 2>$null
cargo --version 2>$null; go version 2>$null; dotnet --version 2>$null
ruby --version 2>$null; conda --version 2>$null; gradle --version 2>$null
brew --version 2>$null
# Linux/Mac Bash 检测
for cmd in python node npm cargo go dotnet ruby conda gradle brew; do
    $cmd --version 2>/dev/null && echo "✓ $cmd available"
done

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:USERPROFILEpip"
Set-Content -Path "$env:USERPROFILEpippip.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:APPDATANuGet"
New-Item -ItemType Directory -Force -Path $nugetPath
Set-Content -Path "$nugetPathNuGet.Config" -Value @"


  
    
    
    
  

"@ -Encoding UTF8
Write-Host "✓ NuGet 已配置为华为云镜像"

Linux/Mac:

mkdir -p ~/.nuget
cat > ~/.nuget/NuGet.Config << 'EOF'


  
    
    
    
  

EOF
echo "✓ NuGet 已配置为华为云镜像"

验证:

dotnet nuget list source

3.6 RubyGems 配置

全局配置:

gem sources --remove https://rubygems.org/ 2>/dev/null || true
gem sources -a https://mirrors.tuna.tsinghua.edu.cn/rubygems/
echo "✓ RubyGems 已配置为清华镜像"

Bundler 项目级配置:

bundle config mirror.https://rubygems.org https://mirrors.tuna.tsinghua.edu.cn/rubygems/
echo "✓ Bundler 镜像已配置"

验证:

gem sources -l

3.7 Conda 配置

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --set show_channel_urls yes
echo "✓ Conda 已配置为清华镜像"

验证:

conda config --show channels

3.8 Maven 配置

mkdir -p ~/.m2
cat > ~/.m2/settings.xml << 'EOF'


  
    
      aliyun
      central
      Aliyun Maven
      https://maven.aliyun.com/repository/public
    
  

EOF
echo "✓ Maven 已配置为阿里云镜像"

3.9 Gradle 配置

方式一:环境变量

# 添加到 init.gradle 或环境变量
echo 'GRADLE_USER_HOME=~/.gradle' >> ~/.bashrc
mkdir -p ~/.gradle/init.d
cat > ~/.gradle/init.d/mirror.init.gradle << 'EOF'
allprojects {
    repositories {
        all { ArtifactRepository repo ->
            if (repo instanceof MavenArtifactRepository) {
                def url = repo.url.toString()
                if (url.startsWith("https://repo.maven.apache.org/maven2") ||
                    url.startsWith("https://jcenter.bintray.com")) {
                    project.logger.lifecycle "Repository ${repo.url} replaced with Tencent mirror."
                    remove repo
                }
            }
        }
        maven { url 'https://mirrors.cloud.tencent.com/nexus/repository/maven-public/' }
        maven { url 'https://maven.aliyun.com/repository/public' }
        mavenCentral()
    }
}
EOF
echo "✓ Gradle 已配置"

方式二:项目级 settings.gradle

dependencyResolutionManagement {
    repositories {
        maven { url = uri('https://mirrors.cloud.tencent.com/gradle/') }
        mavenCentral()
    }
}

3.10 Homebrew 配置 (macOS)

export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
echo "✓ Homebrew 已配置为中科大镜像"

3.11 Composer 配置 (PHP)

composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
echo "✓ Composer 已配置为阿里云镜像"

Phase 4: 验证与反馈

4.1 执行验证命令

配置完成后,Agent 自动运行对应的验证命令(见各小节末尾),并向用户展示结果。

4.2 向用户报告

报告格式示例:
─────────────────────────────────────
✅ 配置完成!已为您配置以下镜像源:

  • pip (Python)     → 阿里云 ⚡ 0.02s
  • npm (Node.js)    → 华为云 ⚡ 0.04s  
  • cargo (Rust)     → 阿里云 ⚡ 0.05s

📋 下次操作建议:
  • 运行 pip install / npm install 测试速度
  • 如需恢复默认配置,请告知我
─────────────────────────────────────

常见问题处理(Agent 参考)

问题 解决方案
配置后仍然慢 清除缓存:pip cache purge / npm cache clean --force
SSL 证书错误 添加 trusted-host 配置(已在上述命令中包含)
权限不足 使用用户级配置(非系统级),避免 sudo
想恢复默认 删除对应配置文件或执行:npm config delete registry / unset GOPROXY
特定项目需要不同镜像 使用项目级配置(.npmrc / .piprc / .cargo/config.toml)

恢复默认配置命令速查

包管理器 恢复命令
pip rm -f ~/.pip/pip.conf 或 del %USERPROFILE%pippip.ini
npm npm config delete registry
yarn yarn config delete registry
pnpm pnpm config delete registry
cargo rm -f ~/.cargo/config.toml
Go unset GOPROXY 并从 shell 配置文件中删除
NuGet 删除 %APPDATA%NuGetNuGet.Config
RubyGems gem sources --remove 并添加回 https://rubygems.org/
Conda conda config --remove channels
Homebrew unset HOMEBREW_BOTTLE_DOMAIN

Agent 执行规范

  1. 直接执行:不要创建脚本文件,直接运行 Shell 命令
  2. 幂等性:配置命令可重复执行,不会产生副作用
  3. 用户确认:修改前简要告知用户将要做什么
  4. 错误处理:如果某个工具未安装,跳过并告知用户
  5. 平台适配:自动检测操作系统,选择正确的命令格式(PowerShell vs Bash)

相关专题

更多
Vite 项目如何打包和部署
Vite 项目如何打包和部署

Vite项目打包部署专题汇集生产构建、产物预览、输出目录、资源路径、Nginx与GitHub Pages部署及常见白屏和路由404问题的已审核文章,帮助读者完成上线流程。

2026.10.28

0

16

Vite 如何搭配 Vue.js
Vite 如何搭配 Vue.js

Vite搭配Vue.js专题汇集创建Vue 3项目、配置开发环境、路径别名、Vue插件、代理、多环境构建与调试的已审核文章,帮助读者完成从初始化到日常开发的配置。

2026.10.28

0

15

Vite 项目目录怎么看
Vite 项目目录怎么看

Vite项目目录专题汇集入口文件、src源码、public静态资源、路径别名、项目根目录和构建输出目录相关的已审核文章,帮助读者理解各文件夹的用途与引用方式。

2026.10.28

0

10

Gradle插件开发入门教程
Gradle插件开发入门教程

本专题介绍Gradle插件开发的基本流程,涵盖插件类编写、自定义任务注册、扩展参数设计和插件应用方法,帮助你理解插件如何组织构建逻辑,减少多个项目之间的重复配置。

2026.10.22

0

11

Gradle Wrapper配置教程
Gradle Wrapper配置教程

本专题介绍Gradle Wrapper的基本作用,涵盖文件组成、生成方法、版本配置和任务调用,帮助你理解项目如何使用指定的Gradle版本,减少不同开发环境带来的构建差异。

2026.10.22

0

10

Golangci-lint检查器使用教程
Golangci-lint检查器使用教程

本专题整理Golangci-lint常用Linters的用途与配置方法,覆盖错误处理、无效代码、安全、复杂度、命名和依赖检查,帮助项目合理选规则。

2026.10.22

0

15

Gradle怎么构建Java项目
Gradle怎么构建Java项目

本专题介绍Gradle Java项目构建方法,涵盖Java插件配置、依赖声明、源码编译、测试执行和打包检查,帮助你理解各阶段的任务关系,逐步完成项目构建。

2026.10.22

0

10

PHP时间戳漏洞修复教程
PHP时间戳漏洞修复教程

本专题汇总PHP常见时间戳漏洞,包括2038年溢出、时区漂移、时间戳伪造、重放攻击、时间盲注与日志审计失效等,并给出升级64位环境、使用 DateTimeImmutable、统一UTC、严格超时校验、预处理绑定、hash_equals 比对等修复方案,帮助开发者快速排查和加固时间相关代码。

2026.10.22

0

25

Golangci-lint配置文件与规则设置
Golangci-lint配置文件与规则设置

本专题聚焦Golangci-lint YAML配置文件,讲清运行参数、规则启停、目录排除、问题过滤及严重级别设置,便于团队统一检查标准。

2026.10.22

0

15

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
热门推荐
/
最新课程
phpStudy极速入门视频教程
phpStudy极速入门视频教程

共6课时 | 54.7万人学习

独孤九贱(4)_PHP视频教程
独孤九贱(4)_PHP视频教程

共89课时 | 134.1万人学习