Systemd services in Ubuntu
How To

Enable or Disable systemd Services in Ubuntu

Sagar Sharma
Sagar Sharma

Table of Contents

Most of the popular Linux distros including Fedora, Ubuntu, and Arch use systemd as an init service which is used to manage services using the systemctl command.

And in this guide, I will walk you through the following:

  • How to enable systemd services (auto start at boot)
  • How to disable systemd services
  • How to start systemd services (run the service)
  • How to stop systemd services
  • How to restart systemd services (stop and run the service)

Check the status first

Before you jump on the shown methods to enable or disable the services, it is important to know the current status of the service.

To check the service, you'd have to use the status flag with the systemctl command as shown here:

systemctl status <service_name>

For example, here, I checked the status of the Apache service:

systemctl status apache2
check status of systemd service in Ubuntu
⚠️
You need superuser privileges to tweak services using systemd in Linux.

How to enable systemd services in Ubuntu

💡
Enabling a service means it will automatically start when the system boots. But it won't run immediately. For that, you have to start a service.

To enable a service, all you have to do is execute the systemctl command in the following manner:

systemctl enable <service_name>

Let's say I want to enable apache service, then, I will be using the following command:

sudo systemctl enable apache2
enable systemd service in Ubuntu

Now, you can check the status of the service by using the status flag as shown:

systemctl status <service_name>
service is not active even after enabling in

As you can see, the service is not active yet as enabling it will start the service when the Ubuntu system reboots next.

But what if you want to start the service imminently? Here's how you do it.

How to start the systemd services in Ubuntu

As I mentioned earlier, even if you want to start the service immediately, you'd have to use the start flag as shown:

systemctl start <service_name>

For example, if I want to start the apache, then, I will be using the following:

sudo systemctl start apache2

And now, if you check the status, it will be active and running:

start service using systemctl in ubuntu

How to disable systemd services in Ubuntu

By disabling the system, you can prevent automatic activation at every boot and to do so, you'd have to use disable flag with the systemctl command as shown:

sudo systemctl disable <service_name>

For example, here, I have disabled the Apache service:

sudo dystemctl disable apache2
disable services using systemctl command

But if you check the status of the service, it would be still running:

check status of service after disabling it

Why? Because the changes will be applied after the next boot.

How to stop systemd services in Ubuntu

As I mentioned above, disabling the service won't get you an immediate effect so if you want to stop the service immediately, here's how to do it.

To stop the service, you'd have to use the stop flag with the systemctl command as shown here:

sudo systemctl stop <service_name>

As I want to stop the Apache service, I will be using the following:

sudo systemctl stop apache2

And now, if you check the status, the service will be stopped:

stop the service using systemctl command in ubuntu

You can create a systemd service on your own

In case you don't know, you can create a systemd service as per your needs. Want to know how? Here's a detailed guide:

How to create a systemd service in Linux
Learn the steps for creating systemd services in Linux with the practical example demonstrated in this tutorial.

I hope you will find this helpful.



Sagar Sharma

Sagar Sharma

A software engineer who loves to tinker with hardware till it gets crashed. While reviving my crashed system, you can find me reading literature, manga, or watering my plants.