This skill helps users speed up the package installation process by automatically detecting the package manager and switching to a high-speed domestic mirror source.
When to Use
Trigger this skill in the following situations:
- The user runs or is about to run any package installation command (npm, pip, yarn, pnpm, brew, apt, gem, cargo, go get, docker, etc.)
- The user complains about slow download speeds or installation timeouts
- The user explicitly mentions switching to a domestic mirror source
- The user wants to speed up package installation
- The user is setting up a new environment or installing project dependencies
Supported Package Managers
This skill supports the following package managers and comes preconfigured with domestic mirror sources:
- Node.js: npm, yarn, pnpm
- Python: pip, pip3
- macOS: Homebrew
- Linux: apt (Ubuntu/Debian), yum (CentOS/RHEL)
- Ruby: gem
- Rust: cargo
- Go: go modules
- Docker: Docker registry mirror
Workflow
Step 1: Detect the Package Manager
Analyze the user's input to identify the package manager they need:
- Look for explicit commands (npm install, pip install, brew install, etc.)
- Check whether files such as package.json, requirements.txt, Gemfile, go.mod, Cargo.toml, etc. exist in the current directory
- If necessary, ask the user: "What type of package do you want to install? (npm, pip, brew, etc.)"
Step 2: Generate the Mirror Switching Script
Create a shell script to switch the detected package manager to a domestic mirror source.
The script should:
- Include only the package managers the user actually needs
- Use reliable, high-speed mirror sources (Tsinghua, Alibaba, Tencent, USTC, etc.)
- Be safe, reliable, and reversible (restore the official source when necessary)
- Output clear prompt information
Use the accompanying scripts/generate_mirror_script.sh(if available), or generate the script inline according to the following mirror configuration:
#!/bin/bash
# npm 镜像
npm config set registry https://registry.npmmirror.com
# pip 镜像
mkdir -p ~/.pip
cat > ~/.pip/pip.conf << 'EOF'
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn
EOF
# Homebrew 镜像(macOS)
if [[ "$OSTYPE" == "darwin"* ]]; then
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"
fi
# Docker 镜像
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]
}
EOF
# 其他包管理器依此类推...
Step 3: Load the Mirror Script
Guide the user to load the generated script:
source /path/to/mirror_switch.sh
Or execute it directly and then run the user's installation command:
. /path/to/mirror_switch.sh && <用户的安装命令>
Note: This operation only sets environment variables for the current shell session. For permanent effect, the script should be added to the shell configuration file (.bashrc、.zshrc etc.).
Step 4: Execute the Installation
After the mirror source configuration is complete, run the user's original installation command.
Mirror Source Recommendations
Use the following reliable mirror sources in order of priority:
- npm:
https://registry.npmmirror.com(Taobao) - pip:
https://pypi.tuna.tsinghua.edu.cn/simple(Tsinghua) - Homebrew: Tsinghua mirror (brew.git, homebrew-core, bottles)
- apt: Tsinghua or Alibaba mirror
- gem:
https://gems.ruby-china.com - cargo:
https://mirrors.ustc.edu.cn/crates.io-index - go:
https://goproxy.cnorhttps://goproxy.io - Docker:
https://docker.mirrors.ustc.edu.cn
Advanced Usage
Manually Select a Mirror
Users can also manually select a mirror and generate a script through the following website: https://www.theaiera.cn/mirrors
This website provides an interactive interface that can:
- Select a specific package manager
- Choose from multiple mirror sources
- Dynamically generate a mirror switching script
- Copy and use the generated script
Permanent Configuration
If permanent mirror source configuration is needed, guide the user to add the mirror settings to the shell configuration file or the package manager configuration file:
# 对于 npm
echo 'export npm_config_registry=https://registry.npmmirror.com' >> ~/.bashrc
# 对于 pip
# ~/.pip/pip.conf 已为永久配置
# 对于 Homebrew
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc
Restore the Official Source
If you need to restore the official source:
# npm
npm config set registry https://registry.npmjs.org
# pip
rm ~/.pip/pip.conf
# Homebrew
unset HOMEBREW_BREW_GIT_REMOTE HOMEBREW_CORE_GIT_REMOTE HOMEBREW_BOTTLE_DOMAIN
Error Handling
If the mirror source becomes unavailable:
- Inform the user that the mirror may be temporarily unavailable
- Suggest trying other mirror sources
- Fall back to the official source if necessary
- Provide troubleshooting tips (check the network, try different mirrors, etc.)
Interaction examples
Example 1: User: "I want to install a new node project, but npm install is too slow" Action: Generate an npm mirror script, load it, then run npm install
Example 2: User: "pip install pandas timed out" Action: Generate a pip mirror script, load it, then run pip install pandas
Example 3: User: "How can I speed up brew install?" Action: Generate a Homebrew mirror script, explain how to load it, then run brew install
Example 4: User: "I am setting up a new development environment and need to install all dependencies" Action: Check package.json, requirements.txt, Gemfile, etc., generate the corresponding mirror script for all detected package managers, load them, then run the install commands
Notes
- If you are unsure which package manager the user needs, be sure to ask and confirm first
- When choosing a mirror source, prioritize speed and reliability
- Be conservative: only configure the package managers the user actually needs
- Explain what the script does before loading it
- Clearly state whether the change is temporary (current session) or permanent