Important: Please read the Qt Code of Conduct -

Qt apt-get installation script for multiple Linux Distributions

  • I'm trying to build a Qt install script for multiple Linux distributions. I know that Ubuntu uses "apt-get" repository and RHEL and CentOS use "yum" repository. What's the best way to detect the distribution in my script.

    I was thinking something like the following just wanted to know the best way to detect the distro.

    if (Ubuntu)
        sudo apt-get install -y [qt package]
    else-if (RHEL or CentOS)
        sudo yum -y install [qt package]

    I found lsb_release on Ubuntu but not on CentOS. So is there a way to detect whether "yum" or "apt-get" is used?

  • Lifetime Qt Champion

    Hi, gives some interesting clues.

    Hope it helps

  • @anshah
    As you found, lsb_release is not always there. In any case, that approach will require you to pre-enumerate which distros you know about use which, too much work to maintain.

    Stick to testing whether apt_get or yum is present, it's much easier, and your script requires it to run anyway. So like:

    if [ -f /usr/bin/apt-get ]
        sudo apt-get install -y [qt package]
    elif [ -f /usr/bin/yum ]
        sudo yum -y install [qt package]

    [edit: fixed executable check SGaist]

Log in to reply