Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way (from a script) to identify the default system package manager?

To clarify, what I want to do is run a given command and, on Debian or any of its derivatives it'll return something like "apt", on openSUSE it'll return "zypp", on Fedora et al it'll return "yum", on Arch Linux it'll return "pacman" etc.

I know I can do this with something like the following, I just wondered if there was a more robust method that won't break as soon as there is an executable with the same name.

which apt >/dev/null 2>&1
if [ $? -eq 0 ]
    echo "apt"
# etc...
share|improve this question

Start with the accepted answer to this question: How can I get distribution name and version number in a simple shell script?. Then, decide which package manager you want to use based on the detected distribution.

share|improve this answer
Is there a readily available list of package managers for different distributions? There are a lot of debian clones in particular. – DrAl Aug 23 '12 at 6:58
Not sure about a readily available list, but all Debian clones will use apt-get. – Jim Paris Aug 23 '12 at 16:52
Yes, I realise that; my problem isn't so much identifying the distribution (although your link will certainly make this easier), it's figuring out how to link a distribution name like (to pick one at random) "SolusOS" with apt without maintaining a list of every distribution that exists. – DrAl Aug 24 '12 at 6:49
Do it the autotools way: Check if it works. BTW, that a distribution uses apt means that it is a Debian relative (and they are a rather compact bunch), finding yum doesn't mean that the packaging conventions (split into library/development, one big brick of Perl or individual packages off CPAN, ...) are the same. Don't even try to install a Fedora package on CentOS (there are at least 3 or 4 years of version skew, just won't work). – vonbrand Jan 18 '13 at 3:28

Instead of identify binary programs, you should start from identify distributions,

Just give you few lines that works in bash scripting:

declare -A osInfo;

for f in ${!osInfo[@]}
    if [[ -f $f ]];then
        echo Package manager: ${osInfo[$f]}

Althrough these parts can't be trusted, but generally people won't do that.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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