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.
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.
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.
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
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
enableis notstart. Useenable --nowto do both. Likewisedisableleaves a running service running unless you add--now.staticmeans no[Install]section. It cannot be enabled directly, but another unit can pull it in withWants=orRequires=.maskis stronger thandisable. A disabled unit can still start through a dependency or by hand; a masked one refuses everything untilunmask.- Edit the unit, then re-enable. Changing
WantedBy=after enabling does not move the old link. Runsystemctl reenable, plussystemctl daemon-reloadif 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 withls -lto see exactly what is enabled. - Aliases and
Also=.Alias=creates extra names andAlso=enables companion units together, so oneenablecan create several links. - Not for timers' schedule. To run a job on a schedule, enable the
.timerunit, not the service it triggers (see Timer units). - Root required for system units;
is-enabledworks for everyone.