Ubuntu更换软件源|apt包管理更换软件源
一.为root创建密码
-
因为Ubuntu新版默认账户不是root,所以在改sources.list文件时会有权限问题,我们先为root账户创建密码
sudo passwd root
然后输入两遍密码
-
之后进入切换到root用户
su root
输入密码
二.Warning: Changing a readonly file报错解决
-
先切换至root用户
然后到/etc/apt/目录下cd /etc/apt/
改变sources.list权限,使用属主赋予权限
chmod u+w sources.list
三.更换软件源
//到/etc/apt/目录下
cd /etc/apt/
//对sources.list文件做一个备份
cp sources.list sources.list
首先到阿里云打开Ubuntu镜像界面
在该界面查找自己Ubuntu版本的软件源
以Ubuntu 20.04为例
deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse # deb https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse # deb-src https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse deb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
使用vi或vim打开sources.list
按下esc,按下gg,再按dG,全部删除
之后将aliyun配置粘贴进去
//使用sudo apt-get update更新软件列表
sudo apt-get update
//使用sudo apt-get upgrade更新软件
sudo apt-get upgrade
四.清华源软件源更换
到清华源找到对应版本进行更换即可