0

I am trying to install an apt package without one of its dependencies (specifically, git without Perl to reduce Docker image size by >50MB).

I can think of two options:

  1. installing the package without this specific dependency
  2. installing the package with all dependencies and removing the dependency afterwards

and I investigated them both, and none of them worked. So my question is: is there a clean way to do it?

Below is what I tried so far.

1. Installing the package without this specific dependency

Most suggestions recommend

apt download git
dpkg --ignore-depends=perl -i git*.deb

Unfortunately this does not install other dependencies, so git clone fails due to the lack of libcurl.

So in order to fix that, some other suggestions recommend using

apt-get -f install

afterwards, but this command tries to install Perl, which is what I am trying to avoid.

Ok, so I am telling to not touch Perl with:

apt-mark hold perl

but then apt-get -f install tries to remove git.

Ok, so the I am telling to leave git alone:

apt-mark hold git

but then apt-get -f install gives up, as it cannot install Perl and it cannot uninstall git. The end of story.

2. installing the package with all dependencies and removing the dependency afterwards

I installed git with Perl:

apt install -y git

then removed Perl with

dpkg -P --force-depends perl

but this does not remove other dependencies that have been brought by Perl eg. perl-modules. So the attempt is unsuccessful.

7
  • 1
    This is wrong way to go, or rather should I say guaranteed way to shoot yourself in the foot. If you want to omit some dependencies, you have to properly rebuild dependent packages without that dependency. It is not that hard. May 17, 2022 at 12:41
  • The thing is that I fully control the system (the Docker image), and I know for sure that perl won't be needed, as git is only used for cloning repositories. Rebuilding git on the other hand would greatly increase the build time of my Docker image. May 17, 2022 at 12:58
  • 2
    If size is an issue, you might want to try another image, like Alpine. It is considerably smaller, and git doesn't have a dependency on perl there.
    – Lacek
    May 17, 2022 at 13:14
  • The problem is that Alpine uses musl instead of glibc, and I don't want to risk instability issues. However it's good to know that there is no dependency on perl there. May 17, 2022 at 13:23
  • 2
    Try repacking the git deb file without that dependency. That's not hard either. Understand, you are trying to use a package manager for its features like dependency resolution (by installing git and the dependencies you need), and at the same time you want to deliberately misuse its dependency resolution capability somehow (to omit some dependencies). That won't work. Debian package manager wasn't built with this in mind. (Portage, Gentoo's package manager did, and it uses something called "USE-flags" for that. But that's completely different story.) May 17, 2022 at 13:51

1 Answer 1

You must log in to answer this question.

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