ubuntu更换安装源和pip镜像源

一、pip源配置

清华pip源地址:https://pypi.tuna.tsinghua.edu.cn/simple
豆瓣pip源地址:https://pypi.doubanio.com/simple/

1. 临时使用

这里以清华的镜像源为例,若要使用其他的源,改变地址就可以了。

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package

2. 设为默认

修改配置文件:~/.config/pip/pip.conf (Linux), (没有就创建一个), 将 index-url改成至tuna,例如
在.config文件夹中创建pip/pip.conf

#创建pip文件夹
sudo mkdir pip
cd pip
#创建pip.cong文件
touch pip.conf
#编辑pip.conf文件
sudo vim pip.conf

在pip.conf文件中添加清华大学的pypi镜像,要是想用其他的镜像,替换成相应的地址即可。

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

二、ubuntu源配置

1. 配置源文件位置

备份并替换/etc/apt/sources.list的源内容,将原文件做一个备份。
命令:cp /etc/apt/sources.list /etc/apt/sources.list.bak

2. 更改源文件内容

在终端输入命令:

sudo vim /etc/apt/sources.list

将文件内容替换成想要更换的源

清华的源

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main multiverse restricted universe

阿里的源

deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse

修改完后还需要更新使其生效

sudo apt-get update 

你可能感兴趣的:(Linux)