更换国内源
pip
国内源
豆瓣 http://pypi.douban.com/simple/
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
阿里云 https://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
临时更换
pip install pythonModuleName -i https://mirrors.aliyun.com/pypi/simple
永久更换
windows
直接在 user 目录中创建一个 pip 目录,如:C:\Users\xx\pip,新建文件 pip.ini,内容如下
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
Linux
#创建目录
mkdir -p ~/.pip
#修改配置文件
vim  ~/.pip/pip.conf
#写入以下内容并保存
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
npm
cnpm(间接换源)
Private npm registry and web for Company.
安装并使用国内淘宝镜像源
npm install cnpm -g --registry=https://r.npm.taobao.org
直接换源
单次使用
npm install --registry=https://registry.npm.taobao.org
永久使用
npm config set registry https://registry.npm.taobao.org
Ubuntu
修改软件源配置文件 sources.list
sudo vim /etc/apt/sources.list
注释掉全部内容(i),在末尾加入如下数据
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
保存退出(Esc,!wq),更新软件
sudo apt-get update
sudo apt-get upgrade
Golang
直接命令行配置
- 
启用 Go Modules 功能 go env -w GO111MODULE=on
- 
配置 GOPROXY 环境变量 # 官方镜像源 go env -w GOPROXY=https://goproxy.io,direct # 阿里镜像源 go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct # 七牛云 CDN go env -w GOPROXY=https://goproxy.cn,direct
- 
验证 source ~/.bashrc后使用命令go env | grep GOPROXY查看配置是否成功。
- 
私有模块 采用自有仓库,不经过镜像,可使用 GOPRIVATE环境变量设置,多个使用逗号隔开。go env -w GOPRIVATE=*.corp.example.com
使用系统环境变量配置
- 
Linux / Mac 配置 echo "export GO111MODULE=on" >> ~/.bashrc echo "export GOPROXY=https://goproxy.cn" >> ~/.bashrc source ~/.bashrc
- 
Windows 配置 单次使用: $env:GO111MODULE = "on" $env:GOPROXY = "https://goproxy.cn"永久使用: 在系统个环境变量编辑器中设置变量 GO111MODULE,值为on;变量GOPROXY,值为goproxy.cn。
银弹
以上更换国内源的方法实在是过于繁杂,更好的方法是使用系统代理直接将本机流量转发到处于正常的网络环境的机器中。参见新文章 为服务器配置畅通的网络环境。