How to completely remove packages with apt-get on Ubuntu Linux?
The other day I was upgrading docker (which is awesome BTW) to the newest version, but the Ubuntu repository already has a docker package which is like 4 versions old. The old docker is actually named "docker.io" so a long time ago I created a symlink from docker.io to docker, but I forgot to remove it before upgrading.
This silly situation left me with an installed but totally unusable docker package. What happened is that lxc-docker couldn't install be installed in /usr/bin/docker because there was another file (a symlink) with the same name. So I removed the symlink /usr/bin/docker, and I reinstalled lxc-docker, only to realize that it didn't work.
I tried several things until I realized that the best way to proceed was to completely remove lxc-docker and install it again. So this is what I did:
[code]sudo apt-get remove --purge lxc-docker[/code]
[code]sudo apt-get install lxc-docker[/code]
You would think that works, except that it doesn't. I then did:
[code]sudo apt-get remove --purge lxc-docker[/code]
[code]sudo apt-get purge lxc-docker[/code]
[code]sudo apt-get install lxc-docker --reinstall[/code]
But again, that didn't work. Turns out, that the correct way to do this is:
[code]sudo apt-get remove --purge lxc-docker[/code]
[code]sudo apt-get autoremove --purge[/code]
[code]sudo apt-get install lxc-docker[/code]
The autoremove is as important as the remove --purge. Conclusions:
- Don't ever symlink to /usr/bin/, use /usr/local/bin instead
- If you want to completely remove a package, you need to autoremove after you remove them. Weird!