1、创建并编辑脚本文件(个人比较顺手nano,vim不会用)
2、脚本内容如下:(脚本为阿里源,版本ubuntu20.04,其他源替换即可)
#! /bin/bash
cp /etc/apt/sources.list /etc/apt/sources.list.bak
echo #阿里云源 > /etc/apt/sources.list
echo deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse >> /etc/apt/sources.list
echo deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse >> /etc/apt/sources.list
echo deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse >> /etc/apt/sources.list
echo deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse >> /etc/apt/sources.list
echo deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse >> /etc/apt/sources.list
echo deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse >> /etc/apt/sources.list
echo deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse >> /etc/apt/sources.list
echo deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse >> /etc/apt/sources.list
echo deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse >> /etc/apt/sources.list
echo deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse >> /etc/apt/sources.list
apt update
apt upgrade
PS:> 代表覆盖文件内容并新增;
>>代表追加到尾部。
因为脚本后面带有更新,所以稍等片刻等待执行完毕,中途会需要按Y确认。
3、赋予脚本执行权限:
PS:有关LINUX执行脚本区别参考:https://blog.csdn.net/u012336923/article/details/50474692
4、执行脚本:(以管理员方式执行)
文章评论