當前位置: 首頁>>技術問答>>正文


我可以用apt刪除apt嗎?

, ,

問題描述

我知道我可以使用apt-get remove <package>刪除程序。

但是apt本身就是一個程序。我可以使用apt-get remove apt來刪除它,還是會在一段時間內混淆?

最佳解決思路

APT允許您使用選項-s模擬命令。您可以自己嘗試,發出命令apt-get -s remove apt(不需要sudo)。

這會產生以下輸出:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  apturl-common xul-ext-ubufox
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
  apt apt-utils apturl nautilus-share python3-software-properties
  software-properties-common software-properties-gtk ubuntu-desktop
  unattended-upgrades
WARNING: The following essential packages will be removed.
This should NOT be done unless you know exactly what you are doing!
  apt
0 upgraded, 0 newly installed, 9 to remove and 0 not upgraded.
Remv ubuntu-desktop [1.341]
Remv nautilus-share [0.7.3-1ubuntu5]
Remv apturl [0.5.2ubuntu9]
Remv software-properties-gtk [0.96.13.1]
Remv software-properties-common [0.96.13.1]
Remv python3-software-properties [0.96.13.1]
Remv unattended-upgrades [0.86.2ubuntu1]
Remv apt-utils [1.0.10.2ubuntu1]
Remv apt [1.0.10.2ubuntu1]

所以答案應該是:是的,你可以。

次佳解決思路

您可以…

sudo apt-get remove apt
Reading package lists... Done
Building dependency tree      
Reading state information... Done
The following packages will be REMOVED:
  apt apt-utils apturl nautilus-share python3-software-properties
  software-center software-properties-common software-properties-gtk
  ubuntu-desktop ubuntu-extras-keyring ubuntu-minimal unattended-upgrades
WARNING: The following essential packages will be removed.
This should NOT be done unless you know exactly what you are doing!
  apt
0 upgraded, 0 newly installed, 12 to remove and 0 not upgraded.
After this operation, 9,031 kB disk space will be freed.
You are about to do something potentially harmful.
To continue type in the phrase 'Yes, do as I say!'
?] Yes, do as I say!
(Reading database ... 179817 files and directories currently installed.)
Removing ubuntu-desktop (1.327) ...
Removing nautilus-share (0.7.3-1ubuntu5) ...
Removing apturl (0.5.2ubuntu4) ...
dpkg: warning: while removing apturl, directory '/usr/lib/python3/dist-packages/AptUrl/gtk/backend' not empty so not removed
Removing software-properties-gtk (0.94) ...
dpkg: warning: while removing software-properties-gtk, directory '/usr/lib/python3/dist-packages/softwareproperties/gtk' not empty so not removed
Removing software-properties-common (0.94) ...
Removing python3-software-properties (0.94) ...
Removing unattended-upgrades (0.82.8) ...
Removing ubuntu-minimal (1.327) ...
Removing apt-utils (1.0.9.2ubuntu2) ...
Removing software-center (13.10-0ubuntu4.1) ...
Removing ubuntu-extras-keyring (2010.09.27) ...
OK
Removing apt (1.0.9.2ubuntu2) ...
Processing triggers for man-db (2.7.0.2-2) ...
Processing triggers for gconf2 (3.2.6-2ubuntu1) ...
Processing triggers for hicolor-icon-theme (0.13-1) ...
Processing triggers for shared-mime-info (1.2-0ubuntu3) ...
Processing triggers for gnome-menus (3.10.1-0ubuntu2) ...
Processing triggers for desktop-file-utils (0.22-1ubuntu2) ...
Processing triggers for bamfdaemon (0.5.1+14.10.20140925-0ubuntu1) ...
Rebuilding /usr/share/applications/bamf-2.index...
Processing triggers for mime-support (3.55ubuntu1) ...
Processing triggers for dbus (1.8.8-1ubuntu2) ...
Processing triggers for libc-bin (2.19-10ubuntu2) ...

並將警告你即將做一些非常具有破壞性的事情。我必須說……包裝清單看起來很可怕,節省的空間不到6000kb:D

它確實完成但無法使用”apt-get”。 Ubuntu軟件中心將不再工作,您需要使用”dpkg”到re-install一個包管理器(並且還需要手動安裝所有依賴項)。

第三種解決思路

有一次,當我運行CoreUbuntu時,我從源代碼安裝了一個錯誤的軟件包,apt決定廢棄的apt。下次我運行apt autoremove時,我實際上沒有看到要刪除的軟件列表,而apt在列表中。

想象一下,下次我輸入apt install <package-name>並獲得The program 'apt' is currently not installed. You can install it by typing: sudo apt-get install apt時我會感到驚訝。

幸運的是,由於某種原因,autoremove沒有去除任何apt的依賴性,所以我所要做的就是wget apt.deb存檔並使用dpkg -i重新安裝。


如其他答案所示,如果您使用apt刪除apt,由於它嘗試解決的依賴關係,您將遇到更多問題。

我發現它很有趣,但確實如此(當然對於Debian,也許在某種程度上可能是Fedora /openSUSE?)許多現代發行版都是基於其所選包管理器提供的基礎設施來定義和構建的。

第四種思路

從技術上講,apt無法刪除apt …因為apt不知道如何刪除,安裝或升級包。安裝,刪除,升級,配置軟件包的任務留給dpkg。雖然你可以告訴apt刪除名為”apt”的包,它的作用是檢查apt包的反向依賴關係,記下這些包並命令dpkg刪除它們。這可以在the other answers中看到。

即使沒有apt,你也可以使用dpkg來安裝,刪除或升級軟件包,隻是跟蹤所需的依賴關係和升級會更加痛苦,這是apt的存在理由。

參考資料

本文由Ubuntu問答整理, 博文地址: https://ubuntuqa.com/zh-tw/article/1707.html,未經允許,請勿轉載。