I have a single binary file that I want to distribute to our users and most of its dependencies are linked statically during build time, but there are few dependencies like leveldb that need to be installed. These dependencies are installed using the apt get install command.

What's the best way to distribute this? My idea is just a simple zip file archive that contains the binary and not to use deb or docker as I feel it is an overkill, but how do I 'automate' the installation of the dependencies? Maybe a bash file like run.sh that contains the apt get install line before running the binary, but how do I check that the dependencies are not yet available before installing them?

  • 3
    Build a package, and declare the dependencies with Depends/Recommends/Suggests lines. You may feel that it's "overkill" but if you don't, your users will "feel" that you are lazy and value your minor convenience over their systems. Also, avoid static linking wherever & whenever you can. If the OS (debian or whatever) has a shared lib, then depend on that rather than bundling or statically linking it.
    – cas
    Jul 28 at 6:55
  • Perhaps apt-cache pkgnames leveldb would show if a package is available? Jul 28 at 22:59

The "best" way is to use the right packaging system for the operating system you are targeting. The entire point of packages is to do exactly what you're describing. Make a deb or rpm or whatever it is you want your users to install.

If you insist on not doing that, then the other common way is to offer a tar.gz file (not a zip!) which contains the binary and a script named configure. These are normally accompanied by Makefiles that compile the source code, but in your case you could simply have the configure script check for the presence of the dependencies and install them if needed. Since you mention apt get, I assume you are only targeting Debian and Debian-derived systems, in which case, checking will be easy since you just need dpkg, so you could do:

dpkg -l | awk '$1=="ii" && $2=="leveldb"' >/dev/null || apt install leveldb

All of this, however, feels wrong: on Debian-based systems, users expect a deb file, that is how programs are distributed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.