Where to put the systemd configuration files

There are many locations for the configuration files of systemd service, I want to know where are they and where to put my own…

Where to put the systemd configuration files

There are many locations for the configuration files of systemd service, I want to know where are they and where to put my own configuration files, here are the description of the locations.

  1. /etc/systemd/system/ : The prime directory for your custom unit files. If you want to add a new service or modify an existing one without affecting the package-provided defaults, this is where you’d place your files.
  2. /lib/systemd/system/ or /usr/lib/systemd/system/: These directories are for unit files installed by packaged software. You should avoid making changes here because package updates can overwrite your modifications.
  3. /run/systemd/system/: This directory is for runtime-generated files. It's typically used for temporary files that should not persist after a reboot.
  4. ~/.config/systemd/user/: For user-specific unit files, this directory allows individual users to manage their services.
  5. /etc/systemd/user/: Similar to the system directory, but for user unit files that are provided by the system administrator.

When you create a new service file for systemd, you’ll want to place it in /etc/systemd/system/. Afterward, remember to reload systemd with systemctl daemon-reload to recognize your new or modified unit files. You can then enable and start your service with systemctl.