Managing system services efficiently is a crucial skill for Linux users, especially system administrators and developers. The systemctl command in Linux is an essential tool that allows you to start, stop, restart, enable, and disable services with ease. Since systemd is the default service manager on most modern Linux distributions—including Rocky Linux, Ubuntu, CentOS, Fedora, and Debian—learning how to use systemctl effectively will enhance your ability to control system processes.
In this guide, we’ll walk you through the systemctl command in Linux, explaining its key functions, usage examples, and best practices.
🚀 For a hands-on tutorial, check out our YouTube video:
What is the systemctl Command in Linux?
The systemctl command in Linux is a command-line tool used to interact with systemd, the service manager responsible for system initialization, process monitoring, and service control. With systemctl, you can:
✅ Start, stop, restart, and check the status of services.
✅ Enable or disable services to start on boot.
✅ Monitor system processes and logs for troubleshooting.
What Runs First on System Boot?
At system startup, systemd is the first process that runs and is assigned PID 1 (Process ID 1). It then initializes all other services.
To check this, run:
You can also visualize system processes with:
Commonly Used systemctl Commands
Let’s go over the most frequently used systemctl commands in Linux, using Apache (httpd) as an example service.
Checking Service Status
To check if a service is running, use:
✅ This helps verify whether Apache is active or has failed.
Starting and Stopping Services
To start a service:
✅ Use this after installing Apache to begin serving web pages.
To stop a service:
✅ Useful for performing maintenance or updates.
Restarting Services
✅ Required after configuration changes to apply new settings.
Enabling and Disabling Services on Boot
To enable Apache to start automatically on boot:
To disable it:
Advanced systemctl Commands
Checking Active Services
To check if a service is running without detailed output:
To list all active services:
Masking and Unmasking Services
To prevent a service from starting, even manually:
To re-enable it:
Rebooting or Halting the System
To reboot:
To halt without restarting:
Understanding systemd Unit Files
Systemd uses unit files to manage services. These files are stored in:
📂 /etc/systemd/system/ – Custom and user-defined unit files.
📂 /lib/systemd/system/ – Default unit files installed by packages.
To find a unit file location:
Working with Logs
To check service logs using journalctl:
✅ This helps diagnose issues that are not immediately visible through systemctl status
.
FAQs
1️⃣ What is the difference between systemctl and service commands?
The service
command is an older method used in SysVinit systems, while systemctl
is part of systemd, which is more powerful and modern.
2️⃣ How do I check all running services using systemctl?
Run:
3️⃣ How do I restart multiple services at once?
You can restart multiple services by running:
4️⃣ Can I use systemctl on non-systemd Linux distributions?
No, systemctl
only works on systemd-based distributions like Rocky Linux, Ubuntu, CentOS, and Fedora.
5️⃣ What should I do if a service fails to start?
Check the status:
Then view logs:
Conclusion
Mastering the systemctl command in Linux is essential for efficient service management. Whether you’re managing servers, deploying applications, or troubleshooting issues, these commands help you keep services running smoothly.
📌 Want a step-by-step walkthrough? Watch our YouTube tutorial here