How to delete broken packages in ubuntu

run this command to remove broken packages in ubuntu.

sudo dpkg --remove --force-remove-reinstreq package_name 

after removing package update your system with command

sudo apt-get update

Ubuntu fix broken package (best solution)

After trying

sudo apt-get update –fix-missing

and

sudo dpkg –configure -a

and

sudo apt-get install -f

the problem of a broken package still exists the solution is to edit the dpkg status file manually.

  1. sudo nano /var/lib/dpkg/status    (you can use vim or gedit instead of nano)
  2. Locate the corrupt package, and remove the whole block of information about it and save the file.

———–

Unlock the dpkg – (message /var/lib/dpkg/lock)

sudo fuser -vki /var/lib/dpkg/lock

sudo dpkg –configure -a

 

For 12.04 and newer:

You can delete the lock file with the following command:

sudo rm /var/lib/apt/lists/lock

You may also need to delete the lock file in the cache directory

sudo rm /var/cache/apt/archives/lock

dpkg: error processing package linux-image-generic (–configure): dependency problems – leaving unconfigured

I had this issue just now. What I did was purge the errant package using dpkg in my case then update and force the reinstall:

sudo dpkg --purge linux-image-3.13.0-35-generic
sudo apt-get update
sudo apt-get -f install

How to get a list of installed packages held back from an upgrade?

You can use apt-mark:

apt-mark showhold

this will show the packages that are kept in “hold” state so that the package manager won’t auto-upgrade the packages.

From man apt-mark:

showhold
           showhold is used to print a list of packages on hold

GPG error when updating, key expired

Error:

Err:13 http://downloads.metasploit.com/data/releases/metasploit-framework/apt lucid InRelease
  The following signatures were invalid: KEYEXPIRED 1474234115  KEYEXPIRED 1474234115  KEYEXPIRED 1474234115
Fetched 98.2 kB in 0s (150 kB/s)
Reading package lists... Done
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://downloads.metasploit.com/data/releases/metasploit-framework/apt lucid InRelease: The following signatures were invalid: KEYEXPIRED 1474234115  KEYEXPIRED 1474234115  KEYEXPIRED 1474234115

Solution:

$ sudo echo 'deb http://apt.metasploit.com/ lucid main' > /etc/apt/sources.list.d/metasploit-framework.list
$ sudo wget -O - http://apt.metasploit.com/metasploit-framework.gpg.key | apt-key add -
$ sudo apt-get update
$ sudo apt-get -y install metasploit-framework

list all packages from a repository in ubuntu / debian

Simple:

grep ^Package: /var/lib/apt/lists/ppa.launchpad.net_*_Packages 

Or more flexible:

grep-dctrl -sPackage . /var/lib/apt/lists/ppa.launchpad.net_*_Packages 

For fancier querying, use apt-cache policy and aptitude as described here:

aptitude search '~O LP-PPA-gstreamer-developers'

How to install missing Perl modules on Debian

  • Use aptitude to see if a prepackaged version exists
    • if the module name is Foo::Bar the packaged version will be called libfoo-bar-perl
    • so do ‘aptitude search libfoo-bar-perl’
    • or just ‘aptitude search foo-bar’
  • Alternatively, install apt-file and use that:
    • To install and set up:
      • apt-get install apt-file
      • apt-file update
    • To search: apt-file search Foo/Bar.pm
    • This is more handy if you get an error giving an explicit filename that Perl can’t find.
    • It is also a bit more reliable than the aptitude way for searching, since it does assume package names follow a pattern, or package descriptions contain the Perl module name.
  • if found, use apt-get to install it
    • ‘sudo apt-get install libfoo-bar-perl’
  • if not found, install from CPAN
    • ‘sudo dh-make-perl –install –cpan Foo::Bar’
  • if that doesn’t work for some reason
    • ‘sudo cpan Foo::Bar’

Docker – Ubuntu – bash: ping: command not found

Docker images are pretty minimal, But you can install ping in your official ubuntu docker image via:

apt-get update
apt-get install iputils-ping

Chances are you dont need ping your image, and just want to use it for testing purposes. Above example will help you out.

But if you need ping to exist on your image, you can create a Dockerfile or commit the container you ran the above commands in to a new image.

Commit:

docker commit -m "Installed iputils-ping" --author "Your Name <name@domain.com>" ContainerNameOrId yourrepository/imagename:tag

Dockerfile:

FROM ubuntu
RUN apt-get update && apt-get install -y iputils-ping
CMD bash