切换国内源大全(收集整理)

众所周知,国内的网络环境太糟糕了,所以收集整理各类服务切换国内源的方法

Ubuntu

命令

1
2
3
4
## 备份系统自带的source列表
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak \
&& sed -i 's/^\(deb\|deb-src\) \([^ ]*\) \(.*\)/\1 http:\/\/mirrors.aliyun.com\/ubuntu \3/' /etc/apt/sources.list \
&& apt-get update

国内镜像源

名称地址
阿里镜像源http://mirrors.aliyun.com/ubuntu
清华大学镜像源https://mirrors.tuna.tsinghua.edu.cn/ubuntu/
网易镜像源https://mirrors.163.com/ubuntu/
东北大学镜像源http://mirror.neu.edu.cn/ubuntu/

CentOS

命令

1
2
3
4
5
6
sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' \
-i.bak \
/etc/yum.repos.d/CentOS-*.repo \
# 更新软件包缓存
&& sudo yum makecache

国内镜像源

名称地址
阿里镜像源http://mirrors.aliyun.com/centos
清华大学镜像源https://mirrors.tuna.tsinghua.edu.cn/centos
网易镜像源https://mirrors.163.com/centos
东北大学镜像源http://mirror.neu.edu.cn/centos

Alpine

命令

1
2
3
cp /etc/apk/repositories /etc/apk/repositories.bak \
&& sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
&& apk update

Docker

命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 修改/etc/docker/daemon.json#registry-mirrors
sudo vim /etc/docker/daemon.json
{
"registry-mirrors":[
"https://registry.cn-hangzhou.aliyuncs.com",
"https://mirror.ccs.tencentyun.com",
"https://05f073ad3c0010ea0f4bc00b7105ec20.mirror.swr.myhuaweicloud.com",
"https://registry.docker-cn.com",
"http://f1361db2.m.daocloud.io",
"https://hub-mirror.c.163.com",
"https://mirror.baidubce.com"
]
}

systemctl daemon-reload
systemctl restart docker

Maven/Gradle

setting.gradle里面修改,Gradle版本6以上

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
pluginManagement {
repositories {
mavenLocal()
repositories {
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
maven { url 'https://maven.aliyun.com/repository/public/' }
}
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositories {
mavenLocal()
maven { url = uri("https://maven.aliyun.com/repository/central") } // central
maven { url = uri("https://maven.aliyun.com/repository/public") } // jcenter & public
maven { url = uri("https://maven.aliyun.com/repository/google") } // google
maven { url = uri("https://maven.aliyun.com/repository/spring") } // spring
maven { url = uri("https://maven.aliyun.com/repository/spring-plugin") } // spring plugin
maven { url = uri("https://maven.aliyun.com/repository/grails-core") } // spring plugin
}
}

Python

命令

1
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

国内镜像源

名称地址
清华源https://pypi.tuna.tsinghua.edu.cn/simple
阿里源https://mirrors.aliyun.com/pypi/simple/
腾讯源http://mirrors.cloud.tencent.com/pypi/simple
豆瓣源http://pypi.douban.com/simple/

NodeJS

命令

1
2
3
$ npm config set registry https://registry.npm.taobao.org
$ npm config get registry
https://registry.npm.taobao.org

参考资料