How do I get apt-get to ignore some dependencies?

Scenario / Questions

How do I make apt-get ignore some dependencies? For example, I wanted to install mailx so I can use it to send email from cron scripts/report-generating tools. However, installing mailx also installs exim4 and a whole bunch of dependencies (I already have Postfix installed) I don’t really need and which I guess mailx can also live without.

How do I ignore some dependencies but still use apt-get since it’s a nice tool?

Find below all possible solutions or suggestions for the above questions..

Suggestion: 1:

Simple and easy solution: just specify the unwanted packages with an extra - after each of them.

Example without the - switch:

root@debian:~# apt-get install bsd-mailx 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  exim4-base exim4-config exim4-daemon-light liblockfile-bin liblockfile1
[...]

Example using the switch to avoid installing exim4-base. Notice the - at the end:

root@debian:~# apt-get install bsd-mailx exim4-base-
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package 'exim4-base' is not installed, so not removed
The following extra packages will be installed:
  liblockfile-bin liblockfile1 ssmtp
[...]

As you can see, apt-get does not try anymore to install the exim4-base package, and it does not try to install its various dependencies (exim4-config etc).

And if you were wrong and needed that exim4-base dependency after all, you can just apt-get install it later!

Suggestion: 2:

You can change the dependencies of a deb package like this:

  1. Unpack deb: ar x golden-linux.deb (will create i.e. three files: debian-binary control.tar.gz data.tar.gz)
  2. Unpack control archive: tar xzf control.tar.gz (will create: postinst postrm preinst prerm md5sums control)
  3. Fix dependencies in control (use a text editor)
  4. Repack control.tar.gz: tar --ignore-failed-read -cvzf control.tar.gz {post,pre}{inst,rm} md5sums control
  5. Repack deb: ar rcs newpackage.deb debian-binary control.tar.gz data.tar.gz (order important! See [Note] )

[Note]: dpkg wouldn’t be able to read the metadata of a package quickly if it had to search for where the data section ended!

Suggestion: 3:

After you install the package with the --ignore-depends option, go and edit the /var/lib/dpkg/status file, and remove whatever dependency you think is not needed.
Just be very careful. In order a dep. to be required, it is more than likely to BE required

Suggestion: 4:

You can try the --nodeps flag with apt-get.
Or download the package and install it using dpkg with the option --ignore-depends.

For example, if you want to install package foo without dependency bar:

dpkg --ignore-depends=bar -i foo_1.2.3_amd64.deb

Suggestion: 5:

Since you installed postfix from source, you need to install a “dummy” package which will satisfy the mail-transport-agent dependency of mailx (or bsd-mailx). The “equivs” package in debian exists to create such a dummy package which you can install to tell dpkg “this dependency is satisfied”

The reason that telling dpkg to simply ignore dependencies is not a good solution, is that you are only telling dpkg/apt to ignore it for a single transaction, you can’t tell it to ignore dependencies forever. Everytime you use apt it checks the dependencies on all packages

Suggestion: 6:

I’ve been looking for this option on a Ubuntu 12.04 Server running Xen. In my domains I use the -virtual kernel, and apt persistently tried to install grub with every kernel package upgrade. Grub however is not needed inside the domU when using p[yv]grub.

I’ve been looking for the -nodeps option to apt-get as well, but it didn’t work, so ended up uninstalling/purging grub* after each kernel upgrade.

After all, really reading a man page helps sometimes – it turns out a similar apt-get option on 12.04 seems to be –no-install-recommends, which actually works in this case, since grub is listed as ‘recommended’ in the package information (I guess so it is not a “real” dependency?).

I’m adding this here because in my case it solved a similar issue, and the hint for ‘–no-install-recommends’ was not mentioned yet.

Suggestion: 7:

An alternate way to manually tweak the dependencies is:

apt-get download yourpackage
dpkg-deb -x yourpackage.deb PackageFolder
dpkg-deb --control yourpackage.deb PackageFolder/DEBIAN
vim PackageFolder/DEBIAN/control
dpkg -b PackageFolder yourpackage2.deb
apt-get install ./yourpackage2.deb

Suggestion: 8:

You can download the package with apt-get and then install it with dpkg, manually listing the dependancy you would like to be ignored.

For example if I want to download mypackage but it depends on libperl5.14 and I dont want to install libperl5.14 as I have a different version I can ignore this dependancy as follow:

apt-get download mypackage
dpkg -i --ignore-depends=libperl5.14 mypackage.deb

Suggestion: 9:

On my debian system, bsd-mailx actually depends on default-mta | mail-transport-agent (you can check what a package depends on with apt-cache show <pkg> for anything in the archive or dpkg -s <pkg> for installed packages.

It may be that your postfix package doesn’t have Provides: mail-transport-agent so apt doesn’t realize you have an MTA installed. It would be worth filing a bug for that if it’s an official package.

Suggestion: 10:

For the purposes of this, you could just install nail which I don’t think has these dependencies?

apt-get install nail

Suggestion: 11:

Well – don’t.

Using other people’s work is very important on the road to any success. When you build some software from source (tarball), you miss the opportunity to use the distro’s package manager’s work.

You won’t get “free” updates. Most of the time none ever updates the packages they installed from source. Because they need to track the software for new versions, rebuild it and all the dependent programs (try to remember them).

You will have problems with other packages from your distribution’s repos. This is exactly the case stated in the question: ubuntu has a great package manager and some very nice people maintaining the packages. And they have decided, that for the mailx program to work you need an MTA. So if you installed postfix from sources ubuntu wouldn’t ask you to install exim.

If for some reason the maintenance of the server passes to some other person (e.g. your project becomes very successful and you decide to hire another guy to manager the servers while you are busy with other stuff) he will naturally expect to run dpkg --get-selections to get all the installed packages.

Try to use the distro’s package management software as much as possible. Learn to build your own packages if you can’t find one prebuilt and you’ll become a better professional.

Disclaimer: This has been sourced from a third party syndicated feed through internet. We are not responsibility or liability for its dependability, trustworthiness, reliability and data of the text. We reserves the sole right to alter, delete or remove (without notice) the content in its absolute discretion for any reason whatsoever.

Source: How do I get apt-get to ignore some dependencies?

Design a site like this with WordPress.com
Get started