I am trying to create an install script for my program that runs on Linux systems. I am choosing Bash for the install script, and I am wondering if there is any efficient way of installing a package independent of the system’s package manager. I know that Debian uses aptitude, Redhat uses yellow dog updater, etc. Given this diversity of package managers, it seems like a lot of if statements will be required, of which check the distribution and match it with the default package manager.
The only thing I can think of apart from checking the distro is having the script manually download the package sources and building them. I’m not sure how popular projects do this, but I would be interested to know.
Advertisement
Answer
You are not the first to encounter this issue. Basically, there are two differnt solutions to that.
Use a package manager
Examples:
Docker detects your OS and adds its own repository to the local package manager. This might be an option for you, depending on your project size.
Standard compile and install approach
You might have heard of the following 3 lines:
./configure make make install
Make is not the only option, there are other build systems, that do essentially the same.
There are still a lot of open source projects out there, where compiling locally and then moving/copying the files to the correct location is the preferred method of installation (sometimes only the development builds)
Examples: