Debian: how to install a package without a specific dependency (git without Perl)

cn flag

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.

Nikita Kipriyanov avatar
za flag
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.
Lukasz Guminski avatar
cn flag
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.
in flag
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.
Lukasz Guminski avatar
cn flag
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.
Nikita Kipriyanov avatar
za flag
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.)
Lukasz Guminski avatar
cn flag
It is interesting. You are basically saying that the root cause is the packaging of git itself, indicating that something like `git-minimal` would be needed. I will investigate repackaging to see if the option is feasible.
djdomi avatar
za flag
or you build it on your own, without perl support if possible, it's really not hard and well documented how to do that on [the debian way](

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.