138

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?

4
  • how is postfix installed? via the debian package? or did you install postfix from source?
    – stew
    Mar 23, 2011 at 20:13
  • Yes, Postfix was installed from source
    – FrancisV
    Mar 23, 2011 at 22:26
  • 5
    Debian's mailx package only 'recommends' exim4, doesn't require it. If you don't want to install recommended packages, just add APT::Install-Recommends "false"; to your apt.conf.
    – ruief
    Jan 23, 2014 at 0:30
  • 1
    I found a satisfactory answer to this over at unix.stackexchange.com; unix.stackexchange.com/a/404449/23542 Jan 28, 2019 at 19:36

13 Answers 13

93

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!

7
  • 8
    This is the best way to avoid installing any specific dependency. The other answers either avoid installing all dependencies, uninstall dependencies after they've been installed, or suggest tediously editing packages.
    – Neil
    Feb 11, 2016 at 0:02
  • 1
    This was exactly what I needed! (installing gnupg2 without pinentry-gtk2 to avoid X deps)
    – lapo
    Aug 27, 2016 at 13:34
  • 4
    That is really great, however, in my case apt-get refuses to install the package with "unmet dependencies" (which I specified using this method). Specifically a 100 megabyte documentation package which I don't care for.
    – Rolf
    Jan 14, 2018 at 22:11
  • 17
    Works only with optional dependencies, not with required ones. Error rmessage: Depends: xxx but it is not going to be installed. You can skip all optional packages with apt-get install --no-install-recommends PACKAGE
    – koppor
    Apr 5, 2018 at 0:06
  • 2
    Also does not work with virtual packages. But see unix.stackexchange.com/a/404449/23542 Jan 28, 2019 at 19:39
83

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!

8
  • 2
    Nice,it solves to me a special case of dependencies for "raring8" to "raring6" but the same version =(, very thanks Jul 18, 2013 at 16:36
  • 1
    Thanks from me too; I had to use this because an application required libmng1.so.1 even though it worked perfectly with a symlink set to libmng1.so.2. apt-get just couldn't be muzzled and kept annoying me about unmet dependencies (even when installing something totally unrelated!). What a load of rubbish concept. Dec 15, 2014 at 2:45
  • 1
    Great solution, thanks. I modified step 2 and 4 a bit: 2. FILES=$(tar zxvf control.tar.gz) to store the file list in a variable. 4. tar zcf control.tar.gz $FILES - create the archive in a single step without pipes or redirects using the original file list (after modification).
    – Brett
    May 23, 2016 at 16:30
  • 3
    Another couple suggestsions. For #4: add --ignore-failed-read so that tar ignores missing files from the rest of the command line. (For example, prerm,postrm are absent from many packages.) Also, the tarballs can be .xz rather than .gz in newer versions of the Debian archive format (e.g. data.tar.xz).
    – Dan Lenski
    Jan 9, 2018 at 17:19
  • 1
    I think does it in a "cleaner" way at serverfault.com/a/859394/312306
    – SebMa
    May 2, 2019 at 16:31
52

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

4
  • 5
    After updating /var/lib/dpkg/status it may be necessary to finish the installation with sudo apt-get -f install (no need to specify a package). Jun 18, 2015 at 9:20
  • Also found here: superuser.com/a/815371/127024.
    – Johann
    Dec 30, 2015 at 19:08
  • 3
    This gives me the creeps, but it worked flawlessly! Dec 19, 2018 at 13:16
  • Is this permanent? As in: Will it survive a system update with the package that you altered being updated?
    – anon
    Dec 15, 2022 at 12:29
31

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
8
  • 60
    Which APT version do you have? Mine (0.8.10) doesn't have such an option.
    – tshepang
    Mar 22, 2011 at 12:25
  • 10
    telling dpkg to ignore depndencies isn't an option for him. It only tells dpkg to ignore the dependencies for THIS transaction, it will try to then satisfy the dependencies or remove the pacakge the next time you do anything.
    – stew
    Mar 23, 2011 at 20:13
  • 3
    you can use apt-get download and then dpkg Jan 8, 2015 at 9:14
  • 9
    --no-install-recommends worked for me. Oct 13, 2016 at 18:45
  • 5
    apt download <package> and dpkg --ignore-depends=bar -i <package> saved my life! THANK YOU!
    – GTodorov
    Sep 18, 2018 at 15:24
21

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

2
  • 5
    See also this answer that links to a tutorial (although it is overly complex) superuser.com/a/416560/128960. Short version is: run equivs-control <name>, edit the file produced to provide the right dependency and have a nice name, then run equivs-build <name> and finally dpkg -i the resulting .deb file.
    – Christian
    Jul 12, 2013 at 7:36
  • 2
    IMHO this is really the nicest solution. All other solutions requested here are a bit too hackish. This one only has to be done once and you can install any software depending on the self-compiled software afterwards... So let's upvote this answer!
    – rugk
    Apr 23, 2016 at 15:36
20

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
12

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
1
  • 6
    Just to mention that this will leave you apt "broken". It will not let you install other packages until you fix the missing dependency.
    – drpexe
    Oct 6, 2016 at 18:42
8

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.

3

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.

2

How To Exclude Packages from Apt-Get Upgrade

  • Using apt

    sudo apt-mark hold package_name

  • Using dpkg

    echo "package_name hold" | sudo dpkg --set-selections

  • Using aptitude

sudo aptitude hold package_name

List markes packages

sudo apt-mark show[hold/auto/manual]

source: https://tecadmin.net/exclude-packages-from-apt-upgrade

1

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

apt-get install nail
0
0

This is one of the reasons I developed lansmtpd. It's not very polished, but I use it currently without either postfix or exim4 installed. (I'll eventually polish it so it's easier to install.)

An additional advantage is that if so configured, email from cron on all machines on the lan will be delivered even if the internet is disconnected.

-6

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .