Linux supports various package managers .These make it powerful to deal with installing softwares and working with them through terminal.Most common apt is really a powerful one to talk about.
They are compressed archive which contain programs and files required to run them.The package distribution system is designed to be robust and simplify the application installation process.
But what if the package install is wrong and we are left with broken pieces.
So today we shall talk about how to fix broken packages in Linux.
Reasons of getting broken package:
- Slow internet can lead to corrupt pkg
- Third party installers might corrupt the packages.
- Some unidentified apps can too make the same condition.
How to fix Broken Package.
First step : – Run an update using below command to update the package.
Flags are the most important to use in Linux commands.Apt is smart in this. So first try to fix or rebuild the source list.It will help determine whether there is any update required or not.
The below command will help with this.
sudo apt update --fix-missing #command rishivant@rishivant-Vostro-3590:~$ sudo apt update --fix-missing [sudo] password for rishivant: Hit:1 http://in.archive.ubuntu.com/ubuntu focal InRelease Get:2 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB] Get:3 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB] Hit:4 http://dl.google.com/linux/chrome/deb stable InRelease Hit:5 http://packages.microsoft.com/repos/code stable InRelease Hit:6 https://scala.jfrog.io/artifactory/debian all InRelease Ign:7 https://scala.jfrog.io/artifactory/debian InRelease Hit:8 https://scala.jfrog.io/artifactory/debian Release Hit:10 https://download.docker.com/linux/ubuntu focal InRelease Hit:11 https://apt.releases.hashicorp.com focal InRelease Ign:12 https://pkg.jenkins.io/debian-stable binary/ InRelease Hit:13 https://pkg.jenkins.io/debian-stable binary/ Release Hit:14 https://deb.nodesource.com/node_16.x focal InRelease Get:16 https://typora.io/linux ./ InRelease [793 B] Hit:17 http://security.ubuntu.com/ubuntu focal-security InRelease Fetched 223 kB in 11s (20.1 kB/s) Reading package lists... Done Building dependency tree Reading state information... Done 1 package can be upgraded. Run 'apt list --upgradable' to see it.
NOTE: The – – fix-missing tells apt to ignore missing pkg and run an update without error.
Step 2: – Force the apt to resolve missing dependencies.
Now use the below command to help apt resolve dependecies issues. This will let apt to insatall missing dependencies forcefully.
sudo apt install -f rishivant@rishivant-Vostro-3590:~$ sudo apt install -f Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: chromium-codecs-ffmpeg-extra gstreamer1.0-vaapi hplip-data libgstreamer-plugins-bad1.0-0 libimagequant0 libllvm11 libva-wayland2 mongodb-database-tools printer-driver-postscript-hp python3-olefile python3-pil python3-renderpm python3-reportlab python3-reportlab-accel Use 'sudo apt autoremove' to remove them. 0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
In the above run you can see the bold context showing the forceful run of apt to fix missing packages.
Everytime it wont be the error due to apt but can also be something behind.
Here comes the dpkg. Sometimes error arises when we work with configuration installation.So here the tool to look is dpkg which solves this error.
Steps followed as below to fix pkg fail during configuration process.
First step: –
1 – Try to run the below command to force dpkg to reset any broken configured packages. –
sudo dpkg --configure -a
2 – If the above doesn’t help then run the below command.
sudo dpkg -l | grep ^..r
The command will list package that require install.
By any chance if you get any package with the above command then try to remove it.
3 – Now use the below command to remove it .
sudo dpkg --purge --force-all [package-name]
This will surely help you with getting your broken package fixed.
After every work done the dont forget the last part to run the below two commands.
sudo apt clean sudo apt update
If you followed well till here then surely your apt will become working again.