What is the difference between "systemctl start" and "systemctl enable"?
Solution 1
systemctl start
and systemctl enable
do different things.
enable
will hook the specified unit into relevant places, so that it will automatically start on boot, or when relevant hardware is plugged in, or other situations depending on what's specified in the unit file.
start
starts the unit right now.
disable
and stop
are the opposite of these, respectively.
This means that when you first install MariaDB, you might want to run systemctl enable mariadb.service
to enable it so it starts on boot. You might also want to run systemctl start mariadb.service
, or just reboot, in order to start MariaDB. To stop MariaDB, run systemctl stop mariadb.service
(it will start again on next boot or when you manually start it). To disable it so it doesn't start on boot anymore, run systemctl disable mariadb.service
.
Update:
As noted in gerardw's answer, starting from version 220, released in may 2015, both enable
and disable
started to take the optional --now
switch in order to also start or stop the unit, depending on the used command.
To both disable and stop a unit with the same command, use systemctl disable mariadb.service --now
. Similarly, to both enable and start a unit, use systemctl enable mariadb.service --now
.
Source: systemctl man page
Solution 2
From the systemctl
manpage:
enable NAME...
Enable one or more unit files or unit file instances, as specified
on the command line. This will create a number of symlinks as
encoded in the "[Install]" sections of the unit files. After the
symlinks have been created, the systemd configuration is reloaded
(in a way that is equivalent to daemon-reload) to ensure the
changes are taken into account immediately. Note that this does not
have the effect of also starting any of the units being enabled. If
this is desired, either --now should be used together with this
command, or an additional start command must be invoked for the
unit.
...
Enabling units should not be confused with starting (activating)
units, as done by the start command. Enabling and starting units is
orthogonal: units may be enabled without being started and started
without being enabled. Enabling simply hooks the unit into various
suggested places (for example, so that the unit is automatically
started on boot or when a particular kind of hardware is plugged
in). Starting actually spawns the daemon process (in case of
service units), or binds the socket (in case of socket units), and
so on.
Essentially, enable
marks the service for starting up on boot, and start
actually starts the service immediately.
Solution 3
As of systemctl version 220, enable and disable support a --now switch to start / stop services concurrent with the enabling / disabling.
e.g. systemctl --now enable foobar.service
Use systemctl --version
to check your installed version.
Related videos on Youtube
Chathurika Senani
Updated on September 18, 2022Comments
-
Chathurika Senani over 1 year
I installed MariaDB server to my machine. While setting up, I was met with the problem of whether I should have it enabled all the time, as the documentation I follow suggests with these steps:
sudo yum install mariadb mariadb-server sudo systemctl start mariadb.service sudo systemctl enable mariadb.service
-
Admin about 7 yearsYou can also
enable
andstart
with the--now
swich ofenable
subcommand, eg:systemctl enable sshd --now
. The same is true fordisable
command to alsostop
the service.
-
-
Tursunboy Tojiev almost 7 years++++ for clear explaination
-
JobHunter69 almost 7 yearsSo when should we type systemctl enable? Everytime we want to run the systemd service?
-
JobHunter69 almost 7 yearswhen should we enable? Do we only need to do it once?
-
muru almost 7 years@Goldname You enable it the first time you need it started on the next boot. Only once is enough,
-
vurp0 almost 7 yearsNo, when you want to make it start automatically. If you want to stop it from starting automatically then you run
systemctl disable
. -
JobHunter69 almost 7 yearsWhat about when we edit it? Will we need to re-enable?
-
muru almost 7 years@Goldname you don't need to reenable it.
-
JobHunter69 almost 7 yearsThanks, and the same goes if the file is moved to a different directory and/or the system is rebooted?
-
Chaminda Bandara over 4 yearsThat means, is the service start as root ? How can I start service as another user on boot ?
-
user3757405 over 4 yearsI just used this successfully in systemctl for systemd 219 (on CentOS 7)
-
gerardw over 4 yearsThe systemd github repo says 220, but perhaps CentOS backported the update. github.com/systemd/systemd/blob/…
-
Samuel over 2 years@ChamindaBandara Use the
--user
option.