How to Fix systemctl: Command Not Found Error On Ubuntu

how to fix systemctl: command not found

0 Comment

5 mins Read

how to fix systemctl: command not found

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.

Your friendly neighborhood writer guiding you through the sea of tech and cloud.

Comments

Leave a Comment

Your email address will not be published. Required fields are marked *


Latest Posts