How to fix a apt-get broken packages in linux

Posted by Md. Mahidul Hasan on 2:46 AM with No comments
Trouble-shooting experience
How to fix a apt-get broken packages in linux

Sometime we have experienced some apt-get broken packages in linux. For that broken package, we get the "apt-get install -f" message if we tried to install any kinds of packages in the box. And the funny thing is eather "apt-get install -f" or "apt-get --purge remove packagename" nothing will work in that periods of time. :D If you are also pulling your hairs for this problem, here is the solution. Do it step by step and check with update and upgrade to see problem's present status. If the problem still exits then move forwards to the next steps.

# Update your package list:
mahidul@mahidul:~$ sudo apt-get update

# Clean up any partial packages:
mahidul@mahidul:~$ sudo apt-get autoclean

# Clean up the apt cache:
mahidul@mahidul:~$ sudo apt-get clean

# Clean up any unneeded dependencies:
mahidul@mahidul:~$ sudo apt-get autoremove

# Identify the broken package and forcefully remove it:
mahidul@mahidul:~$  sudo dpkg --remove --force-all packagename
i.e.
mahidul@mahidul:~$  sudo dpkg --remove --force-all mysql-server-5.5

# Manually remove the package and again remove the offending packages. You have to remove broken package related softwares too, i.e
mahidul@mahidul:~$ cd /var/lib/dpkg/info
mahidul@mahidul:/var/lib/dpkg/info$ sudo rm mysql-server*
mahidul@mahidul:~$  sudo dpkg --remove --force-all mysql-server-5.5

# Now uninstall the service normally:
mahidul@mahidul:/var/lib/dpkg/info$ sudo apt-get --purge remove mysql-server

# Now update and upgrade your server for the final time:
mahidul@mahidul:/var/lib/dpkg/info$ sudo apt-get update
mahidul@mahidul:/var/lib/dpkg/info$ sudo apt-get upgrade

Yepee!!!... Problem is solved now. :D