Accidentally Removed apt and apt-get on Ubuntu

2019年12月20日 5444点热度 3人点赞 2条评论
内容目录

Recently, while installing software, I accidentally removed Ubuntu's apt, apt-get, etc., and at that moment, I felt like I was in deep trouble.

It prompted me to enter some text to confirm... I thought it was to confirm the installation, until I saw a bunch of "Removing..." messages.

(Reading database ... 149416 files and directories currently installed.)
Removing unattended-upgrades (1.1ubuntu1.18.04.8) ...
Removing apt-utils (1.8.4) ...
Removing apt (1.4.9) ...
Removing libapt-pkg-dev:arm64 (1.8.2) ...
Removing libapt-pkg5.90:arm64 (1.9.5) ...
Removing apport (2.20.9-0ubuntu7.9) ...
Removing command-not-found (18.04.5) ...
Removing landscape-common (18.01-0ubuntu3.2) ...
Removing ubuntu-standard (1.417) ...
Removing language-selector-common (0.188.1) ...
Removing python3-apport (2.20.9-0ubuntu7.9) ...
Removing software-properties-common (0.96.24.32.7) ...
Removing python3-software-properties (0.96.24.32.7) ...
Removing update-manager-core (1:18.04.11.9) ...
dpkg: warning: while removing update-manager-core, directory '/var/lib/update-manager' not empty so not removed
Removing ubuntu-release-upgrader-core (1:18.04.30) ...
Removing python3-commandnotfound (18.04.5) ...
Removing python3-update-manager (1:18.04.11.9) ...
Removing python3-distupgrade (1:18.04.30) ...
Removing python3-apt (1.6.3ubuntu1) ...
Setting up apt-transport-https (1.4.9) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for dbus (1.12.2-1ubuntu1.1) ..

Then the apt and apt-get commands stopped working... Damn...

I found methods online, but none worked...

Fortunately, there's always a way out. After some effort, I finally got it fixed.

First, go to http://mirrors.163.com/debian/pool/main/a/apt/ to download the corresponding packages.
Download all packages that match your system's CPU.

Make sure to download one of each type of deb package, and select versions based on your actual situation; do not download the latest one!

For example, mine is Ubuntu 18.04 ARM64, and I downloaded these:

.
├── apt-doc_1.4.9_all.deb
├── apt-transport-https_1.4.9_arm64.deb
├── apt-utils_1.4.9_arm64.deb
├── apt_1.4.9_arm64.deb
├── libapt-inst2.0_1.4.9_arm64.deb
├── libapt-pkg-dev_1.4.9_arm64.deb
└── libapt-pkg5.0_1.4.9_arm64.deb

Upload them to an empty directory in Linux. Then, for each .deb package, run:

dpkg -x {xxx.deb} /

Yes, it’s a bit tedious, but you have to persevere.

After running dpkg -x for all the above packages, execute:

dpkg -i *.deb

Don’t worry about any errors reported.

After the execution is complete, immediately run:

apt

If it works normally, then very good.

痴者工良

高级程序员劝退师

文章评论