Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท Systemd and Logging (Read-Only)

systemctl enable and disable

How systemctl enable and disable work: the symlinks they create from the [Install] section, the --now flag, preset, mask and how to check what is enabled.

systemctl enable UNIT tells systemd that a unit should start automatically in the future, and systemctl disable UNIT removes that instruction. Neither command starts or stops anything by itself: they only change what happens at the next boot (or when a target they are attached to is started).

The mechanism is simple. Enabling reads the [Install] section of the unit file and creates symbolic links, for example /etc/systemd/system/multi-user.target.wants/nginx.service pointing at the real unit file. When systemd reaches multi-user.target during boot, it starts everything linked in that .wants directory. Disabling deletes those links.

Terminal
sudo systemctl enable nginx
sudo systemctl enable --now nginx
sudo systemctl disable --now nginx
systemctl is-enabled nginx

Try it

The sandbox has no systemd and no root, so real enable calls are read-only here. These examples build a miniature copy of the link layout in a temporary directory so you can see what enable does.

Bash Enable is just a symlink (simulated)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Reading is-enabled style answers (simulated)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
systemctl enable  [--now] [--user] [--runtime] [--force] UNIT...
systemctl disable [--now] [--user] [--runtime] UNIT...
systemctl reenable UNIT...
systemctl is-enabled UNIT...
systemctl preset UNIT...
systemctl mask UNIT...   ;   systemctl unmask UNIT...
Name Description
--now With enable, also start the unit now; with disable, also stop it now.
--user Act on the per-user service manager instead of the system one.
--runtime Create the links in /run, so they vanish at reboot.
--force Overwrite existing links that point somewhere else.
reenable Disable, then enable again; refreshes links after the [Install] section changed.
preset Apply the distribution's policy files (/usr/lib/systemd/system-preset/) to enable or disable the unit.
mask Link the unit to /dev/null so nothing, not even a dependency, can start it.

Returns: 0 on success. is-enabled prints one word (enabled, disabled, static, masked, alias, indirect, generated...) and exits 0 only for the enabled-like states.

Errors and edge cases: enabling a unit whose [Install] section is empty prints that the unit has no installation config and does nothing; such a unit is static and can only start through a dependency or manually.

Usage notes

  • enable is not start. Use enable --now to do both. Likewise disable leaves a running service running unless you add --now.
  • static means no [Install] section. It cannot be enabled directly, but another unit can pull it in with Wants= or Requires=.
  • mask is stronger than disable. A disabled unit can still start through a dependency or by hand; a masked one refuses everything until unmask.
  • Edit the unit, then re-enable. Changing WantedBy= after enabling does not move the old link. Run systemctl reenable, plus systemctl daemon-reload if you edited the file.
  • Where the links live. System links go in /etc/systemd/system/<target>.wants/; user links in ~/.config/systemd/user/. Look at them with ls -l to see exactly what is enabled.
  • Aliases and Also=. Alias= creates extra names and Also= enables companion units together, so one enable can create several links.
  • Not for timers' schedule. To run a job on a schedule, enable the .timer unit, not the service it triggers (see Timer units).
  • Root required for system units; is-enabled works for everyone.