How to Fix “Systemctl Command Not Found” Error in Linux

System Error

A quick fix to resolve the issue with the ‘systemctl’ command and introduction of some efficient alternatives to it

systemctl being an important utility in the Linux ecosystem, it is very common that you may encounter a problem “systemctl: command not found” error when you try to run the systemctl command. This may not be the case for all the distributions of Linux, but you can probably encounter this error when you are using an older version of the Linux distribution which does not support the systemctl command.

The problem occurring to you is a very common issue and can be easily fixed. So, do not worry at all and just go through the complete tutorial to find a quick and easy fix.

We will try to understand the problem first and then fix it.

Insights into systemctl and systemd

As the error is with reference to the systemctl command, it would be good to know the basics of this command to understand the fix for this error better.

systemctl is a command-line utility Linux offers, which is used to monitor and control one other command-line utility named ‘systemd‘. It also inspects and controls the system manager along with the ‘systemd‘ utility.

General syntax:

systemctl [option] [name]

systemd is a bundle of daemons, libraries and utilities which controls the programs that run when your system boots up. systemd also manages to initiate an important job like starting a journal of system activity.

This utility functions as the central management utility for most if not all of the Linux-based operating systems.


Root cause of the error

The most probable cause for this error might be that you are using an older version of the Linux distribution. Many of the older versions use the SysV init instead of the systemd utility.

systemd utility is absent in the previous Linux versions as it is a recent addition to the basket of utilities provided by Linux. systemctl is compatible to function and monitor with the systemd utility and will fail to work with the previous configurations like SysV init or Upstart.

If you aren’t using systemd, then this error is expected. It is as simple and straightforward as that.

You may encounter this error in the following way.

gaurav@ubuntu:~$ sudo systemctl start ufw
[sudo] password for gaurav:
sudo: systemctl: command not found 
gaurav@ubuntu:~$ 

Here, we attempted to start the Ubuntu Fire Wall (ufw) using the systemctl command and encountered the “systemctl: command not found” error.

So, what to do now if you do not wish to change your current Linux distribution which is using some other central management utility other than systemd? Well, we do have a quick fix for you which would allow you to keep your current Linux distribution as well as fix your error in no time.

Let us observe the fix now.


Fixing “systemctl: command not found” error

Finally, let us now look at the solution of the problem in question after analyzing the causes and basic facts about the problem.

Fix 1: Replacing systemctl with service command

A simple fix for the error in question is to use the service command instead of the error causing systemctl command.

service command helps in running the SystemV init script which is used by the older Linux distributions. If you do not wish to install the systemd utility on your system, this fix will surely work for you.

You can start, restart or stop any services and daemons on your Linux distribution using the service command.

The service command and the systemctl command function in the same way, the only difference here is the compatibility of the command with the utilities that are responsible for the graceful running of your system.

Let us see the service command with an illustration.

General Syntax:

sudo service [service_name] [action]

In the above syntax, the [action] space may include actions like start, stop, restart or status.

We’ll run the same command to start the ufw service using the service command.

sudo service ufw start

Output:

gaurav@ubuntu:~$ sudo service ufw start
gaurav@ubuntu:~$ sudo service ufw status
● ufw.service - Uncomplicated firewall
   Loaded: loaded (/lib/systemd/system/ufw.service; enabled; vendor preset: enab
   Active: active (exited) since Mon 2020-09-28 11:22:34 IST; 1h 5min ago
     Docs: man:ufw(8)
  Process: 333 ExecStart=/lib/ufw/ufw-init start quiet (code=exited, status=0/SU
 Main PID: 333 (code=exited, status=0/SUCCESS)

Sep 28 11:22:34 ubuntu systemd[1]: Started Uncomplicated firewall.
Warning: Journal has been rotated since unit was started. Log output is incomple

Here, the service command is used instead of the systemctl command and it worked out absolutely fine.

Let us see one more example of the service command to get a proper understanding of it.

sudo service apache2 start

Output:

gaurav@ubuntu:~$ sudo service apache2 status
● apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: 
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: active (running) since Mon 2020-09-28 11:22:47 IST; 1h 16min ago
  Process: 1172 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCE
 Main PID: 1248 (apache2)
    Tasks: 55 (limit: 4456)
   CGroup: /system.slice/apache2.service
           ├─1248 /usr/sbin/apache2 -k start
           ├─1249 /usr/sbin/apache2 -k start
           └─1250 /usr/sbin/apache2 -k start

Sep 28 11:22:43 ubuntu systemd[1]: Starting The Apache HTTP Server...
Sep 28 11:22:47 ubuntu apachectl[1172]: AH00112: Warning: DocumentRoot [/var/www
Sep 28 11:22:47 ubuntu apachectl[1172]: AH00558: apache2: Could not reliably det
Sep 28 11:22:47 ubuntu systemd[1]: Started The Apache HTTP Server.

gaurav@ubuntu:~$ 

We have used the service command to start the apache2 utility. Using the status option with the service command will display the current status of the service. We will get the details whether it is running or is dead (inactive).

Let us now use the stop action to stop the apache2 service using the service command.

gaurav@ubuntu:~$ sudo service apache2 stop
gaurav@ubuntu:~$ sudo service apache2 status
lines 1--1...skipping...
● apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: inactive (dead) since Mon 2020-09-28 12:42:06 IST; 1s ago
  Process: 4928 ExecStop=/usr/sbin/apachectl stop (code=exited, status=0/SUCCESS)
  Process: 1172 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
 Main PID: 1248 (code=exited, status=0/SUCCESS)

Sep 28 11:22:43 ubuntu systemd[1]: Starting The Apache HTTP Server...
Sep 28 11:22:47 ubuntu apachectl[1172]: AH00112: Warning: DocumentRoot [/var/www/html] does not exist
Sep 28 11:22:47 ubuntu apachectl[1172]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using ::1. Set the 'S
Sep 28 11:22:47 ubuntu systemd[1]: Started The Apache HTTP Server.

From the detailed examples explained above, we can conclude that we can use this command instead of the systemctl command to control and monitor other daemons and services under the Linux distribution.

Fix 2: Checking for systemd package

Sometime it may be the case that only the systemd package installation may fix the problem. First, you need to check the installation status of the systemd package on your system.

Use the following command to check the package on your system.

sudo dpkg -l | grep systemd

If the systemd utilty is already installed you will get an output similar as shown below.

gaurav@ubuntu:~$ sudo dpkg -l | grep systemd
[sudo] password for gaurav: 
ii  dbus-user-session                             1.12.2-1ubuntu1.2                                amd64        simple interprocess messaging system (systemd --user integration)
ii  libnss-systemd:amd64                          237-3ubuntu10.42                                 amd64        nss module providing dynamic user and group name resolution
ii  libpam-systemd:amd64                          237-3ubuntu10.42                                 amd64        system and service manager - PAM module
ii  libsystemd0:amd64                             237-3ubuntu10.42                                 amd64        systemd utility library
ii  libsystemd0:i386                              237-3ubuntu10.42                                 i386         systemd utility library
ii  networkd-dispatcher                           1.7-0ubuntu3.3                                   all          Dispatcher service for systemd-networkd connection status changes
ri  python3-systemd                               234-1build1                                      amd64        Python 3 bindings for systemd
ii  systemd                                       237-3ubuntu10.42                                 amd64        system and service manager
ii  systemd-sysv                                  237-3ubuntu10.42                                 amd64        system and service manager - SysV links
gaurav@ubuntu:~$ 

If you get an output similar to this, it means that systemd is installed on your system.

If it’s not installed, you can install it in the following way.

sudo apt-get update
sudo apt-get install systemd

If it is installed and still the error persists, then try reinstalling it using the following command.

sudo apt-get install --reinstall systemd

This will solve your problem by installing the systemd utility.


Conclusion

We learnt to fix the “systemctl: command not found” in this tutorial. We can safely conclude that using the service command instead of the systemctl is a good idea and resolves the issue very well. We can easily use the service command after understanding the illustrative examples shown in the tutorial.