137

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?

FrancisV
  • 1,766
  • 3
  • 16
  • 18
  • how is postfix installed? via the debian package? or did you install postfix from source? – stew Mar 23 '11 at 20:13
  • Yes, Postfix was installed from source – FrancisV Mar 23 '11 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 '14 at 00:30
  • 1
    I found a satisfactory answer to this over at unix.stackexchange.com; https://unix.stackexchange.com/a/404449/23542 – artfulrobot Jan 28 '19 at 19:36

13 Answers13

92

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!

Neil
  • 2,425
  • 8
  • 36
  • 45
Jealie
  • 1,054
  • 8
  • 7
  • 7
    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 '16 at 00:02
  • 1
    This was exactly what I needed! (installing `gnupg2` without `pinentry-gtk2` to avoid X deps) – lapo Aug 27 '16 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 '18 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 05 '18 at 00:06
  • 2
    Also does not work with virtual packages. But see https://unix.stackexchange.com/a/404449/23542 – artfulrobot Jan 28 '19 at 19:39
  • 1
    @artfulrobot using `equivs` to create a pseudo-package to satisfy dependencies is a brilliant solution! – Gwyneth Llewelyn Sep 19 '20 at 00:07
  • 1
    This does not work. E.g. ubuntu-minimal won’t install without vim-tiny. Even though I have tilde installed as a stopgap drop-in replacement so I can free myself of the vim/Emacs reality distortion bubble. (They are both abysmal and badly designed editors, and everyone’s in denial. Took me 20 years to stop believing the delusion.) – Evi1M4chine Dec 15 '22 at 12:05
82

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!

Dan Lenski
  • 357
  • 2
  • 12
Janus Troelsen
  • 1,114
  • 1
  • 8
  • 18
  • 2
    Nice,it solves to me a special case of dependencies for "raring8" to "raring6" but the same version =(, very thanks – Felipe Alcacibar Jul 18 '13 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. – syntaxerror Dec 15 '14 at 02:45
  • +1 This worked perfected for me as well. Package `gnome-settings-daemon` wanted `gnome-settings-daemon-schemas=3.8.6.1-0ubuntu11` but I already have `gnome-settings-daemon-schemas=3.8.6.1-0ubuntu11.2` (<- notice the ".2" on the end). This procedure allowed me to edit the package and force it to use the newer 11.2 version. THANK YOU! – Eric Duncan Feb 26 '15 at 15:34
  • 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 '16 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 09 '18 at 17:19
  • Very good. I installed `mssql-server` (14.0.3023.8-5) on `Ubuntu 18.04` by removing the version of `openssl` from depency. And thanks to @DanLenski for informing about the new debian packages (`data.tar.xz`) – mtoloo Apr 19 '18 at 13:20
  • 1
    I think does it in a "cleaner" way at https://serverfault.com/a/859394/312306 – SebMa May 02 '19 at 16:31
  • For the new debian packages that are compressed as .tar.xz, replace the `z` argument in the various `tar` commands with a _capital_ `J` to make it filter through xz instead of gzip; i.e. `tar xJf control.tar.xz` and `tar --ignore-failed-read -cvJf control.tar.xz {post,pre}{inst,rm} md5sums control` – Doktor J Nov 23 '21 at 21:59
51

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

warvariuc
  • 358
  • 1
  • 5
  • 14
Manolis
  • 527
  • 4
  • 2
30

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
thom_nic
  • 141
  • 1
  • 8
Bart De Vos
  • 17,911
  • 6
  • 63
  • 82
20

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

stew
  • 9,388
  • 1
  • 30
  • 43
  • 5
    See also this answer that links to a tutorial (although it is overly complex) http://superuser.com/a/416560/128960. Short version is: run `equivs-control `, edit the file produced to provide the right dependency and have a nice name, then run `equivs-build ` and finally `dpkg -i` the resulting .deb file. – Christian Jul 12 '13 at 07: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 '16 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
AndrewHarvey
  • 301
  • 2
  • 3
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
A.Badger
  • 251
  • 2
  • 5
  • 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 06 '16 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.

memartin
  • 81
  • 1
  • 1
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.

Andy
  • 159
  • 3
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

Cha
  • 21
  • 1
1

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

apt-get install nail
jamespo
  • 1,698
  • 12
  • 12
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.

Ken Jackson
  • 113
  • 4
-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.

skarap
  • 733
  • 5
  • 7