Ubuntu之软件包管理 (最全最精)
1. Ubuntu与Cenots的关系
CentOS之前的地位:Fedora稳定版-->发布-->RHEL稳定版-->发布-->CentOS
CentOS如今的地位:Fedora稳定版-->发布-->CentOS Stream-->发布-->RHEL
从Redhat收购CentOS,到IBM收购Redhat,这是最大的一次变化。但同时也是一个机会,让我们跳出舒适圈,去接触其他优质稳定的企业级系统了。如 Debian、Ubuntu等等。
Centos与Ubuntu的区别:
Centos VS (含Ubuntu)的区别
软件包后缀
centos: *.rpm
Ubuntu *.deb
源配置文件:
修改完源后需执行apt update
Centos: /etc/yum.repolist.d/
清华大学: https://mirrors.tuna.tsinghua.edu.cn/help/centos/
阿里云开源镜像站: https://developer.aliyun.com/mirror/centos?spm=a2c6h.13651102.0.0.3e221b118zsOVM
Ubuntu: /etc/apt/sources.list
清华大学: https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
阿里云开源镜像站: https://developer.aliyun.com/mirror/ubuntu?spm=a2c6h.13651102.0.0.3e221b118zsOVM
网卡配置文件:
Centos: /etc/sysconfig/network-scripts/
Ubuntu: /etc/netplan/00-installer-config.yaml
1.2 apt软件包管理
1.2.1 安装软件包
root@ubuntu-06:/etc/apt# apt install vim
Reading package lists... Done
Building dependency tree
Reading state information... Done
vim is already the newest version (2:8.0.1453-1ubuntu1.8).
vim set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
1.2.2 移除软件包
root@ubuntu-06:/etc/apt# apt remove curl -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
libcurl4
Use 'apt autoremove' to remove it.
The following packages will be REMOVED:
curl pollinate ubuntu-server
0 upgraded, 0 newly installed, 3 to remove and 0 not upgraded.
After this operation, 500 kB disk space will be freed.
(Reading database ... 67415 files and directories currently installed.)
Removing ubuntu-server (1.417.5) ...
Removing pollinate (4.33-0ubuntu1~18.04.2) ...
Removing curl (7.58.0-2ubuntu3.19) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
1.2.3 移除软件包及配置文件
root@ubuntu-06:/etc/apt# apt purge nginx
1.2.4 刷新存储库
root@ubuntu-06:/etc/apt# apt update
1.2.5 升级所有可用软件包
apt upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
1.2.6 自动删除不需要的包
root@ubuntu-06:~# apt autoremove
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
1.2.7 在升级软件包自动处理依赖关系
root@ubuntu-06:~# apt full-upgrade
1.2.8 搜索应用
root@ubuntu-06:~# apt search nginx
1.2.9 显示安装细节
root@ubuntu-06:~# apt show nginx
Package: nginx
Version: 1.14.0-0ubuntu1.11
Priority: optional
Section: web
Origin: Ubuntu
1.2.10 列出所有包
列出所有包
root@ubuntu-06:~# apt list
列出所有已安装的包
root@ubuntu-06:/etc# apt list --installed
列出所有可升级的包
root@ubuntu-06:/etc# apt list --upgradable
1.2.11 安装源中指定的所有版本
root@ubuntu-06:/etc# apt-cache madison nginx
nginx | 1.14.0-0ubuntu1.11 | http://mirrors.aliyun.com/ubuntu bionic-updates/main amd64 Packages
nginx | 1.14.0-0ubuntu1.11 | http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 Packages
nginx | 1.14.0-0ubuntu1 | http://mirrors.aliyun.com/ubuntu bionic/main amd64 Packages
查看这个包有哪些依赖
root@ubuntu-06:/etc# apt-cache depends nginx
nginx
|Depends: nginx-core
|Depends: nginx-full
|Depends: nginx-light
Depends: nginx-extras
|Depends: nginx-core
|Depends: nginx-full
|Depends: nginx-light
Depends: nginx-extras
1.3 dpkg包管理
1.3.1 安装软件包
dpkg -i package.deb
1.3.2 卸载软件包
# 不建议、不自动卸载依赖它的包
root@ubuntu-06:~# dpkg -r package.deb
# 删除包(包括配置文件)
root@ubuntu-06:~# dpkg -P package.deb
1.3.3 使用dkpg查看软件包
#列出当前已经按照的包,类似于rpm -qa
root@ubuntu-06:~# dpkg -l
1.3.4 列出该包所包含的文件
#列出该包所包含的文件,类似于rpm -ql
root@ubuntu-06:~# dpkg -L package
1.3.5 查看文件所属的那个包
root@ubuntu-06:/etc# dpkg -S sshd
openssh-server: /etc/pam.d/sshd
vim-runtime: /usr/share/vim/vim80/syntax/sshdconfig.vim
openssh-server: /usr/share/openssh/sshd_config.md5sum
cloud-init: /etc/systemd/system/sshd-keygen@.service.d/disable-sshd-keygen-if-cloud-init-active.conf
cloud-init: /etc/systemd/system/sshd-keygen@.service.d
openssh-server: /usr/sbin/sshd
openssh-server: /usr/share/man/man5/sshd_config.5.gz
openssh-server: /usr/share/openssh/sshd_config
openssh-server: /usr/share/man/man8/sshd.8.gz
1.3.6 列出deb包中的所有文件
root@ubuntu-06:/etc# dpkg -c xxx.deb
我们一直奔跑在进步的旅途