banner
NEWS LETTER

Ubuntu更换软件源

Scroll down

Ubuntu更换软件源|apt包管理更换软件源Ubuntu 换源

Excerpt

因为Ubuntu新版默认账户不是root,所以在改sources.list文件时会有权限问题,我们先为root账户创建密码然后输入两遍密码之后进入切换到root用户su root输入密码。


Ubuntu更换软件源|apt包管理更换软件源

一.为root创建密码

  • 因为Ubuntu新版默认账户不是root,所以在改sources.list文件时会有权限问题,我们先为root账户创建密码

    1
    sudo passwd root

    然后输入两遍密码

  • 之后进入切换到root用户

    1
    su root

    输入密码

二.Warning: Changing a readonly file报错解决

  • 先切换至root用户
    然后到/etc/apt/目录下

    1
    cd /etc/apt/

    改变sources.list权限,使用属主赋予权限

    1
    chmod u+w sources.list

三.更换软件源

1
2
3
4
//到/etc/apt/目录下
cd /etc/apt/
//对sources.list文件做一个备份
cp sources.list sources.list

首先到阿里云打开Ubuntu镜像界面

在这里插入图片描述

在该界面查找自己Ubuntu版本的软件源

在这里插入图片描述

以Ubuntu 20.04为例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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配置粘贴进去

在这里插入图片描述

1
2
3
4
//使用sudo apt-get update更新软件列表
sudo apt-get update
//使用sudo apt-get upgrade更新软件
sudo apt-get upgrade

四.清华源软件源更换

清华源找到对应版本进行更换即可

其他文章
请输入关键词进行搜索