One of the most powerful and handy tools for Linux users, especially modern distros like Ubuntu, is the systemctl command. This command-line utility is typically used to interact with systemd, the system, and the service manager.
Through the command, you can manage system services, view their status, start or stop them, and enable and disable them at system startup. Pretty handy, right? But if the systemctl command is not found or recognized, youāre going to face the āsudo:systemctl: command not foundā error.
So, letās talk about what the āsystemctl: command not foundā error means, the various reasons why youāre facing this error, and how to fix this error.
What Does systemctl: Command Not Found Mean?
Simply put, the “systemctl: command not found” error means that the systemctl command-line utility is not available or accessible in the current environment. This can be due to a host of reasons, which all come back to either the environment being a non-system environment or the systemd package not being installed on the system.
Basically, the systemd package is not installed, or your Linux distro or version doesnāt use systemd; rather, it uses older service management systems like init.d. One other possibility is that the PATH environment variable doesnāt include the directory where systemctl is located, meaning your shell canāt find it.
Now that you have an idea of what could be wrong with your system, leading to the “systemctl: command not found” error, letās look at how you can verify where your problem lies and how to fix it.
Fixing the systemctl: Command Not Found Error
In the following steps, we’re going to verify whether your system has systemd installed and uses systemctl or not, as well as check systemctl’s path. Once weāve verified the issue, weāre going to take the necessary steps to fix the error.
1. Verifying If Your System Uses systemd
Since Ubuntu systemctl can only be used if you have the systemd package installed, weāre first going to check whether your system is supposed to use systemd by running the following command:
ps -p 1 -o comm=
Or you can check the systemd version with the following command:
systemd --version
If the output is systemd, then systemd is your init system and should have Ubuntu systemctl installed. However, if the output is init or another process manager, it means your system is using an alternative initialization system, and systemctl wonāt work unless you migrate to systemd.
If you see older initialization systems like Upstart or SysVinit and want to switch to systemd to use systemctl, follow these steps:
1. Install systemctl by installing systemd using the following command:
sudo apt install systemd-sysv
2. Reboot your system by running this command:
sudo reboot
3. Check that your system is now using systemd:
ps -p 1 -o comm=
The output should be systemd now.
2. Ensuring systemd Is Installed Correctly
Under normal circumstances, when systemd is installed and is running as your init system, the systemctl command should work correctly. If it’s not, then that means the systemd package is either missing or improperly installed.
Note that if youāre using a minimal version of Ubuntu, such as a Docker container or cloud instance, then systemd may not have been installed by default. To install systemctl through installing systemd, run the following commands:
sudo apt update sudo apt install systemd
Once installed, check to see if the systemctl command is available.
3. Checking systemctlās PATH
One common issue with the systemctl not found error is that systemctl could be installed, but it is not in your systemās PATH. To check whether or not systemd binaries exist in typical directories where itās located, like /bin, /usr/bin, or /usr/local/bin, you can use the following command:
which systemctl
If systemctl is found in any of your directories listed in PATH, you should get an output like this:
/usr/bin/systemctl
If systemctl is not found in any of the directories in PATH, the which command will return nothing.
However, systemctl might still not work even though it’s found in your directories. This is because systemctl could be located in a directory thatās not included in the PATH. In this situation, youāll have to verify whether the directory where systemctlās located is part of your system by using the following command:
echo $PATH
The output should be something like this:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Now, all you have to do is check whether the directory that systemctl resides in (which you got from the which command) is included in the directories listed in the output from the echo $PATH command.
If systemctlās directory is not included in echo $PATHās output, youāll have to add it to your PATH variable. To do this, youāll have to run the following command:
For Bash shell users, open the ~/.bashrc file in a text editor:
nano ~/.bashrc
Add the following line at the end of the file:
export PATH=$PATH:/usr/bin
/usr/bin is a typical directory where systemctl is located in this example.
Now, save and close the file by pressing CTRL + X, then Y to confirm, and Enter to save.
For Zsh users, Open the ~/.zshrc file in a text editor:
nano ~/.zshrc
Add the following line at the end of the file:
export PATH=$PATH:/usr/bin
/usr/bin is a typical directory where systemctl is located in this example.
Now, save and close the file by pressing CTRL + X, then Y to confirm, and Enter to save.
Once youāre done with the above steps, use the echo $PATH command to verify whether your systemctlās directory has been added to your PATH. Now, you should be able to run systemctl without running into the “systemctl: command not found” error.
4. Reinstalling systemd
If the previous fixes donāt work and youāre still facing the command not found error, reinstalling systemd completely might resolve the issue. To do this, run the following commands:
sudo apt purge systemd sudo apt install systemd
Then, reboot your system with this command:
sudo reboot
Check to see if the systemctl works.
5. Verifying systemd Is Correctly Configured
Sometimes, the issue could be as simple as a misconfigured installation of systemd, resulting in a “systemctl: command not found” error. All you have to do to fix this issue is to run the following command, and youāre done:
sudo dpkg-reconfigure systemd
6. Outdated Windows Subsystem for Linux (WSL)
On the off chance youāre using Ubuntu under WSL (Windows Subsystem for Linux) you should know that the older versions of WSL, such as WSL 1, do not natively support systemctl, so no matter which of the previous fixes you use, you wonāt be able to run systemctl.
If you want to take advantage of systemctlās functions, youāll have to upgrade to WSL 2, which has better support for systemd. If youāre unsure whether or not youāre using WSL, you can check by using the following command:
uname -a
If the output mentions WSL, then thatās why youāre seeing the “systemctl: command not found” error.
7. Using sudo Service As an Alternative to systemctl
If you’re facing the”systemctl: command not found” error because your system doesn’t use systemd, you can use the sudo service command to manage services. This command works with older init systems like SysVinit or Upstart. This is useful for Ubuntu systems that rely on init scripts instead of systemd.
For example, to start a service, you would run:
sudo service <service_name> start
Final Thoughts
systemd and its systemctl command-line utility have replaced most other older init systems like SysVinit and Upstart. While systemd may not be everyoneās cup of init system tea due to its monolithic design and non-Unix philosophy, systemd is still generally considered as the prevalent choice. So, hopefully, youāve been able to resolve your systemctl command not available error, as not being able to use systemdās command-line utility severely limits its capabilities.
FAQ
What is systemctl and What Does systemctl: Command Not Found Mean?
systemctl is a command-line tool used to manage services in Linux systems running systemd, such as Ubuntu. The “systemctl: command not found” error occurs when the tool isn’t available or accessible, usually because the system doesn’t use systemd or the systemd package isn’t installed.
Is systemctl available on all versions of Ubuntu?
No, systemctl is not available on all versions of Ubuntu. systemctl is part of the systemd init system, which is the default in most modern Ubuntu versions (from 15.04 onwards). Older versions or certain minimal installations may use alternative init systems like SysVinit or Upstart instead.