FUNDAMENTALS A Complete Guide for Beginners
The systemctl command is used in Linux to manage the system and services. It is one of the most used commands in modern Linux distributions and is used to control the system and services managed by the system and service manager known as systemd. With the systemctl command, you can start, stop, restart, enable, disable, and manage daemons and services on the system.
If you get a “systemctl command not found” error, it usually means that the system and service manager is not installed on your system. It may also indicate that you are trying to run systemctl
without sufficient privileges. The following section of this article will elaborately discuss how you can fix the issue while working with systemctl command.
What Causes the “systemctl Command Not Found” Error?
The “systemctl command not found” error can occur due to several reasons:
- The systemd package is not installed in the system
- Using an older version of the Linux distribution that provides SysV init system instead of systemd, which doesn’t support systemctl commands.
- The PATH environment variable does not have the systemctl directory.
2 Ways to Fix “systemctl command not found” Error in Linux
The ways of fixing your “systemctl command not found” Error in Linux are provided below:
1. Installing the “systemctl” Package
In most cases, the installation of the systemd package can resolve the issue. But before installation, check your system’s installation status for the systemd package:
sudo dpkg -l | grep systemd
If your system has the systemd utility, you will likely get the following output to your command line.
But, if you do not get the output as the image depicted above, you have to install the systemd in the first place. You can install it using your package manager. For example, on Debian–based systems like Ubuntu, you can install it with:
sudo apt-get update
sudo apt-get install systemd
However, If you notice any error due to a broken package, install systemd using the command below:
sudo apt-get install --reinstall systemd
Thus, you can eliminate “systemctl command not found” error.
2. Adding “systemctl” to PATH Environment Variable
If you don’t have a systemctl command in your PATH environment variable then you won’t be able to manage services on your Linux system. It is because you can’t run systemctl directly without specifying the entire path to your executable. systemctl command is usually found in /bin or /usr/bin on most Linux distros that use systemctl as their init system. By adding /usr/bin (or the appropriate directory containing systemctl) to the PATH environment variable, you will be able to execute systemctl commands without specifying the full path, thereby resolving the issue caused by its absence in the PATH.
There are two ways you can add “systemctl” to path environment variable:
A. Temporary solution (for the current session only):
To quickly ensure the availability of the systemctl command in your current shell session, use the following command:
export PATH=$PATH:/usr/bin
This command appends /usr/bin, which is the common location for the systemctl executable, to the existing PATH. This change will only persist for the current shell session.
B. Permanent solution (for all future sessions):
To ensure that the systemctl command is permanently available in all future sessions, follow the instructions given below to add the directory to the PATH variable:
-
To open and edit shell configuration file, use the following command:
nano ~/.bashrc
- Append the following line to the configuration file:
export PATH=$PATH:/usr/bin
This command will add the /usr/bin directory to the current PATH variable. Thus the directory will be available for all future shell sessions.
- Now, save the file with CTRL+O and close the nano editor with CTRL+X short key.
- Manually reload the .bashrc file using the following command:
source ~/.bashrc
This command executes the .bashrc file and updates changes for all shell session.
How to Alter systemctl if “systemctl command not found” Error Still Exists?
If you encounter “systemctl command not found” error and you are looking for an alternative way to manage the system, you can replace the systemctl
command with the service
command. The service command is one of the command-line tools used to control system services on a Unix-like operating system. It is used to start, stop, restart, and query the status of services as the systemctl
command does. Both commands are under systemd package management. Therefore, you can use the service
command without issue as long as the systemd package is installed on your system.
The syntax for the service
command is:
service <service_name> <action>
Here, <service_name>
is the name of the service you want to manage. <action>
is the action you want to perform on the service, such as start, stop, restart, reload, status, etc.
For example, To start the Uncomplicated Firewall (UFW) service on a Linux system, use the following command:
sudo service ufw start
sudo service ufw status
As you see, to enable and check the status of ufw, here the service command is used instead of systemctl command.
Conclusion
The “systemctl command not found” error in Linux can lead you to inefficient system management. But to fix it, you need to make sure it is installed and configured properly. Also, it is important to check if your Linux distribution uses systemd. This article illustrates some ways to fix the problem. However, if you have any problems or questions related to this, feel free to comment below. I am one click away from commenting back. Thank you!
People Also Ask
How to fix systemctl not found?
To fix the “systemctl command not found” error, follow the steps:
- Check if systemd is installed using
dpkg -i | grep systemd
- Add the path of the systemctl to ~/.bashrc file using
export PATH=PATH:$(which systemctl)
- If systemd is not installed, install it using
sudo apt-get install -y systemd
- In case the error is due to non-root user, use systemctl with sudoprevilege.
How to install systemctl command in Ubuntu?
To install the systemctl
command in Ubuntu, you need to ensure that the systemd package is installed and properly configured on your system. You can install it using the package manager with sudo apt-get install systemd.
What is the alternative command to Systemctl?
service
is another command that can be used instead of systemctl
. Whereas systemctl is mainly used to manage and control systemd services, service is a simple command that lets you run, pause, restart, allow, and deactivate system services, no matter what init system your Linux distribution uses.
Where is systemctl located in Linux?
The systemctl command is typically located in the /bin directory or /usr/bin directory. You can find the exact location of the systemctl binary by using the which systemctl command. This command will output the full path to the systemctl binary on your system. Typically, it will be either /bin/systemctl or /usr/bin/systemctl, depending on your Linux distribution and configuration.
Related Articles
- [Fixed] “bash: sudo: command not found” Error
- [Solved] Bash “yarn” Command Not Found Error
- [Solved] Bash “docker” Command Not Found Error
- [Fixed] “bash: ng: command not found” Error
- [Fixed] “bash: java: command not found” Error
- Solved “bash: yum: command not found” [RHEL, Fedora, CentOS]
- [Solved] “bash: vim: command not found” Error
- [Fixed] “bash: curl: command not found” Error
- [Solved] “bash: node: command not found” Error
- [Solved] “bash: code: command not found” Error
<< Go Back to [Solved] “bash: command not found” Error | Bash Error Handling and Debugging | Bash Scripting Tutorial