Ubuntu apt-get和pip源更换

本文详细介绍如何更换Ubuntu系统的apt-get数据源至国内交通大学源,以提升软件包下载速度,并提供pip源更换教程及默认Python版本修改方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用国内的数据源,是为了提高安装包的下载速度。

更换apt-get数据源:

vim /etc/apt/sources.list

例如,更换为交通大学数据源:

# deb cdrom:[Ubuntu 16.04.4 LTS _Xenial Xerus_ - Release amd64 (20180228)]/ xenial main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://ftp.sjtu.edu.cn/ubuntu/ xenial main restricted
deb-src http://ftp.sjtu.edu.cn/ubuntu/ xenial main restricted universe multiverse #Added by software-properties

## Major bug fix updates produced after the final release of the
## distribution.
deb http://ftp.sjtu.edu.cn/ubuntu/ xenial-updates main restricted
deb-src http://ftp.sjtu.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse #Added by software-properties

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://ftp.sjtu.edu.cn/ubuntu/ xenial universe
# deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial universe
deb http://ftp.sjtu.edu.cn/ubuntu/ xenial-updates universe
# deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://ftp.sjtu.edu.cn/ubuntu/ xenial multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial multiverse
deb http://ftp.sjtu.edu.cn/ubuntu/ xenial-updates multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://ftp.sjtu.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://ftp.sjtu.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu xenial partner
# deb-src http://archive.canonical.com/ubuntu xenial partner

deb http://ftp.sjtu.edu.cn/ubuntu/ xenial-security main restricted
deb-src http://ftp.sjtu.edu.cn/ubuntu/ xenial-security main restricted universe multiverse #Added by software-properties
deb http://ftp.sjtu.edu.cn/ubuntu/ xenial-security universe
# deb-src http://security.ubuntu.com/ubuntu xenial-security universe
deb http://ftp.sjtu.edu.cn/ubuntu/ xenial-security multiverse
# deb-src http://security.ubuntu.com/ubuntu xenial-security multiverse

刷新:

sudo apt-get update
sudo apt-get upgrade

pip3的安装与升级:

sudo apt-get install python3-pip
sudo pip3 install --upgrade pip

查看pip版本:

pip -V

pip源更换:

在当前用户的主目录下创建 .pip 文件夹:

mkdir ~/.pip

在.pip文件夹下新建文件pip.conf:

vim .pip/pip.conf

编辑内容如下:

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

这个更换的是清华的源,清华的源5分钟同步官网一次,建议使用。
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
阿里云 http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣(douban) http://pypi.douban.com/simple/
中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/

修改默认python版本
我们也可以把Ubuntu的默认python版本号进行修改,步骤如下:

删除原有Python连接文件

sudo rm /usr/bin/python

建立指向Python3的连接:

ln -s /usr/bin/python3.6 /usr/bin/python

以上操作就是完成默认Python版本设置,
查看默认版本号:

python -V

原文链接(部分删改):https://www.cnblogs.com/vipstone/p/9038023.html

转载于:https://www.cnblogs.com/xujingrong/p/9723632.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值