在本文中,我们将讨论用于从基于 Ubuntu/Debian 的服务器上定位和卸载软件的各种方法和技术。 我们将主要在命令行上使用 apt 和 dpkg 命令。
使用 Apt 卸载软件
各种操作系统使用不同的命令进行包管理,这些命令旨在安装和卸载软件。 要在 Ubuntu 上与这些包进行交互,我们通常希望使用 apt 或 dpkg 命令。 您将在下面的说明中多次看到这些可用命令。 让我们开始吧!
找到要卸载的软件
在删除软件之前,最好找到并记下整个软件标题以确保准确性。 运行以下命令并记下软件或应用程序的名称。
root@host:~# apt list -i
使用“apt list”命令会输出服务器上已安装软件的完整列表。 由于输出的速度,此输出可能难以分类。 为了解决这个问题,我们将使用“less”命令来更轻松地找到软件标题。 这使我们可以滚动浏览标题,从而更容易识别软件。
root@host:~# apt list -i | less
Listing...
accountsservice/bionic,now 0.6.45-1ubuntu1 amd64 [installed]
acl/bionic,now 2.2.52-3build1 amd64 [installed]
acpid/bionic,now 1:2.0.28-1ubuntu1 amd64 [installed]
adduser/bionic,bionic,now 3.116ubuntu1 all [installed]
...
...
...
xxd/bionic-updates,bionic-security,now 2:8.0.1453-1ubuntu1.1 amd64 [installed]
xz-utils/bionic,now 5.2.2-1.3 amd64 [installed]
zerofree/bionic,now 1.0.4-1 amd64 [installed]
zlib1g/bionic,now 1:1.2.11.dfsg-0ubuntu2 amd64 [installed]
root@host:~#
使用 grep 和 apt list 命令进一步缩小搜索范围,使查找已安装软件更加简单。
root@host:~# apt list -i | grep cowsay
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
cowsay/bionic,bionic,now 3.03+dfsg2-4 all [installed]
root@host:~#
在这种情况下,我们搜索了 cowsay。 在定位软件时,Ubuntu 提醒我们不要在脚本中使用 apt,因为可能会出现一些异常情况。 我们没有以这种方式使用 apt,因此我们可以放心地忽略此警告。 如您所见,输出向我们显示了标题、Ubuntu 版本、软件版本以及有关应用程序的其他详细信息。
卸载软件
从 Ubuntu 中删除软件或应用程序相对简单。 在这个 example,我们将向您展示如何从 Ubuntu 中删除“cowsay”软件。
root@host:~# apt-get remove cowsay
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
linux-headers-4.15.0-13 linux-headers-4.15.0-13-generic linux-image-4.15.0-13-generic
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
cowsay
0 upgraded, 0 newly installed, 1 to remove and 1 not upgraded.
After this operation, 89.1 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 126599 files and directories currently installed.)
Removing cowsay (3.03+dfsg2-4) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
root@host:~#
删除和清除软件
在某些情况下,卸载应用程序后可能会留下配置文件。 如果您想从服务器中完全删除软件和任何其他配置文件,我们可以使用命令中的清除标志执行“apt-get remove”。
root@host:~# apt-get remove --purge cowsay
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
linux-headers-4.15.0-13 linux-headers-4.15.0-13-generic linux-image-4.15.0-13-generic
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
cowsay*
0 upgraded, 0 newly installed, 1 to remove and 1 not upgraded.
After this operation, 89.1 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 126599 files and directories currently installed.)
Removing cowsay (3.03+dfsg2-4) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
root@host:~#
移除依赖
如果您想删除与应用程序关联的任何依赖项和库,可以使用“apt-get autoremove”清理命令。
root@host:~# apt-get autoremove
root@host:~# apt autoremove
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
linux-headers-4.15.0-13 linux-headers-4.15.0-13-generic linux-image-4.15.0-13-generic
0 upgraded, 0 newly installed, 3 to remove and 1 not upgraded.
After this operation, 163 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 126541 files and directories currently installed.)
Removing linux-headers-4.15.0-13-generic (4.15.0-13.14) ...
Removing linux-headers-4.15.0-13 (4.15.0-13.14) ...
Removing linux-image-4.15.0-13-generic (4.15.0-13.14) ...
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.15.0-13-generic /boot/vmlinuz-4.15.0-13-generic
update-initramfs: Deleting /boot/initrd.img-4.15.0-13-generic
run-parts: executing /etc/kernel/postrm.d/x-grub-legacy-ec2 4.15.0-13-generic /boot/vmlinuz-4.15.0-13-generic
Searching for GRUB installation directory ... found: /boot/grub
Searching for default file ... found: /boot/grub/default
Testing for an existing GRUB menu.lst file ... found: /boot/grub/menu.lst
Searching for splash image ... none found, skipping ...
Found kernel: /boot/vmlinuz-4.15.0-74-generic
Found kernel: /boot/vmlinuz-4.15.0-72-generic
Found kernel: /boot/vmlinuz-4.15.0-13-generic
Replacing config file /run/grub/menu.lst with new version
Found kernel: /boot/vmlinuz-4.15.0-74-generic
Found kernel: /boot/vmlinuz-4.15.0-72-generic
Replacing config file /run/grub/menu.lst with new version
Updating /boot/grub/menu.lst ... done
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.15.0-13-generic /boot/vmlinuz-4.15.0-13-generic
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.15.0-74-generic
Found initrd image: /boot/initrd.img-4.15.0-74-generic
Found linux image: /boot/vmlinuz-4.15.0-72-generic
Found initrd image: /boot/initrd.img-4.15.0-72-generic
done
root@host:~#
在这种情况下,没有与软件相关的特定依赖项。 尽管如此,系统确实注意到旧内核版本并将其删除,然后自动使用较新的内核版本更新系统。
使用 dpkg 卸载软件
我们可以用来卸载软件的第二种方法是使用 dpkg 命令。 dpkg 也可用于定位和删除已安装的软件。
root@host:~# dpkg --remove package-name
要删除 .deb 文件,我们可以像这样使用“-r”标志:
root@host:~# dpkg -r package.deb
要从已安装软件包的完整列表中进行选择,我们使用带有 dpkg 的“-l”标志来获取当前部署在服务器上的完整软件名册。 我们还可以将此命令的输出通过管道传输到“less”中,以便更轻松地搜索软件标题。
root@host:~# dpkg-query -l | less
为了进一步缩小搜索范围,我们可以将 dpkg-query 命令的输出通过管道传输到 grep 中以定位已安装的软件。
root@host:~# dpkg-query -l | grep cowsay
ii cowsay 3.03+dfsg2-4 all configurable talking cow
root@host:~#
最后,如果我们只知道要卸载的软件名称的一部分,我们可以使用 grep 命令,名称的一部分用一对单引号表示。 此请求将搜索 dpkg-query 的输出并输出可用选项的候选列表,如下所示:
root@host:~# dpkg-query -l | grep partial_name'
root@host:~# dpkg-query -l | grep 'cow'
ii cowsay 3.03+dfsg2-4 all configurable talking cow
root@host:~#
这里的所有都是它的! 您现在知道从 Ubuntu 服务器定位和卸载软件的多种方法。
我们希望您能加入我们!
在这个技术飞速发展的时代,Liquid Web 提供的不仅仅是最广泛的托管产品和服务选择。 我们将我们的时间、才能和经验奉献给您。 我们将自己定义为 Hosting® 中最有帮助的人,因为我们相信您越需要技术来推动业务发展,就越需要专家、有爱心的人站在您身边。
给我们打电话 800.580.4985,或打开 聊天 或与我们联系,立即与我们知识渊博的解决方案团队或经验丰富的托管顾问交谈,以了解更多信息!