When /opt is not enough
I know, you can install your own programs in /opt. Doing that is fully compliant with the Filesystem Hierarchy Standard. However, there is one problem: programs need to be updated. When it comes to one-time copying of files to the device, /opt is a reasonable choice. When you need to do it properly, I recommend using a package manager.
Starting work with this technique can be difficult — it is another technology that you need to learn. However, it has so many advantages that learning it is really an investment.
What package manager can do for me?
Version management
Version control systems are standard when it comes to tracking changes in code. Package managers are a perfect addition to this, as they give us control over the versions of compiled files. Version number is a requirement for working with package management.
If the version number is entered correctly into the package, the package manager will compare versions for us and decide whether an update is needed.
Packaging
Package managers pack the indicated files into an archive using appropriate compression. One less thing to do.
Pre- and post- installation and uninstallation
When a project is complicated enough, installation requires executing commands — beyond just unpacking the files. A typical example are services — after installing new software, we want the service to turn on automatically.
The same goes for uninstalling software. We usually want to clean up after the application and turn off services. This may seem unnecessary, as many packages in embedded systems are not supposed to be uninstalled. Well, never say never. Also, uninstallation is technically a part of upgrade — many package managers work in this way. When upgrading, they first uninstall the old version, and then install the new one.
The package manager will take care of this for us, we just need to provide the appropriate files. Some of them even have an extensive retry system, in case our scripts return an error. For example, if during the uninstallation of the previous version, something fails, package managers can try to execute scripts from the newer version. This helps in fixing problems that would otherwise be hard to fix.
Dependencies
When distributing software using a given package manager, we enter its ecosystem and can easily indicate which other packages need to be installed for our program to work correctly. This simplifies the installation instructions. Now we do not need to contain a list of packages that must be installed first in README or other manual.
Security
Package managers support various security mechanisms, including code signing. If you are looking for a way to establish chain of trust for entire software stack, this is the way to go.
Availability
Package managers are tightly coupled with Linux distributions. For example, Debian-based distros come with dpkg, Fedora uses rpm, and you can easily find others.
If you are building your system using Yocto, look at package-management option for Image Features.
Familiarity
By distributing software using a package manager, you don’t have to explain to anyone how to install it — you can just redirect them to the package manager’s documentation.
Summary
Package managers combine many functions into a single tool specialized in the installation, uninstallation, and updating of files. Using them brings a lot of benefits, some of which may not be apparent in the beginning. If you are working with a modular architecture in a Linux system, where you rely on files installed in the filesystem, a package manager is the best way to work with that.
