Ubuntu换源与apt操作
1 Ubuntu换源
Ubuntu系统通过apt工具安装软件时,可能会失败,我们可以将Ubuntu的源换成国内的。
具体操作步骤如下:
-
更换源之前先安装 apt-transport-https和ca-certificates
sudo apt-get install apt-transport-https ca-certificates
-
更换源
# 备份源 sudo cp /etc/apt/sources.list /etc/apt/sources.list.back # 清空sources.list sudo echo > /etc/apt/sources.list # 编辑并保存sources.list sudo vi /etc/apt/sources.list
将下面内容贴到/etc/apt/sources.list并保存。
清华源:
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释 deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse # 预发布软件源,不建议启用 # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
阿里源:
deb http://mirrors.aliyun.com/ubuntu/ xenial main deb-src http://mirrors.aliyun.com/ubuntu/ xenial main deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main deb http://mirrors.aliyun.com/ubuntu/ xenial universe deb-src http://mirrors.aliyun.com/ubuntu/ xenial universe deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates universe deb http://mirrors.aliyun.com/ubuntu/ xenial-security main deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security universe
或者用命令自动替换,如替换为阿里源
sudo sed -i "s@http://.*archive.ubuntu.com@http://mirrors.aliyun.com@g" /etc/apt/sources.list sudo sed -i "s@http://.*security.ubuntu.com@http://mirrors.aliyun.com@g" /etc/apt/sources.list
-
重新更新并且安装你需要安装的软件。
sudo apt-get update sudo apt intall xxx
2 Ubuntu的apt与apt-get命令
Ubuntu用apt与apt-get命令来管理系统中的包,如包的安装、更新、升级和删除。
apt命令与apt-get命令略有差别,简单来说就是:
apt = apt-get、apt-cache 和 apt-config 中最常用命令选项的集合
普通用户可以忽略这些差异,apt逐渐代替apt-get(可能不会完全取代),但建议直接使用apt。
功能 | apt-get | apt |
---|---|---|
安装软件包 | apt-get install | apt install |
卸载软件包 | apt-get remove | apt remove |
更新所有软件包 | apt-get upgrade | apt upgrade |
更新所有软件包(自动处理依赖关系) | apt-get dist-upgrade | apt full-upgrade |
查找软件包 | apt-cache search | apt search |
查询软件包详细信息 | apt-cache show | apt show |
卸载不必要的依赖关系 | apt-get autoremove | apt autoremove |
删除包以及配置文件 | apt-get purge | apt purge |
列出已安装的、可用的或需要升级的软件包 | 无 | apt list --installed apt list --upgradeable |
打开源代码。在编辑器中列出待编辑的文件 | 无 | apt edit-sources |
参考: