How to find out the default package manager in my system?

889 views Asked by At

I'm starting to manage my dotfiles in my linux mint(ubuntu system). So, here I am writing a bash script automating the installation of my preferred apps. But I want that script to be system independent. Suppose when I become a mature user in linux system, I might want to switch to arch or something that's why I want to make dynamic scripting file which doesn't throw an error because my script says to download apps using apt or apt-get package manager and my system has pacman or dnf package manager.

How can I find out the system package manager?

1

There are 1 answers

0
Bram On

If you want to manage systems on multiple distributions I recommend to look at a configuration management tool instead of writing something yourself.

The skills learned will be valuable in other situations as well.

Configuration management tools like ansible, chef or puppet have already solved the problem of determining the package manager of a specific distribution. (And will often hide the details in a more generic module.)

Also keep in mind that even with this information you will have to take into consideration that distributions can and do use different names for the same package. E.g. Red Hat based distributions have a package called httpd for the apache web server. Debian based distributions will use apache2 packages instead.

Again configuration management tools allow you to define variables for each distribution family.