---
title: "Fix apt and systemctl command not found errors on Linux · CloudSat"
description: "Fix apt: command not found and systemctl: command not found by checking your distro, PID 1 and PATH, then using the right package or service tool."
url: https://cloudsat.io/learn/fix-apt-and-systemctl-command-not-found
updated: 2026-11-18T12:00:00Z
source: CloudSat (https://cloudsat.io/). Prices in USD.
---

[Linux](https://cloudsat.io/learn/topic/linux)

# Fix apt and systemctl command not found errors on Linux

Fix apt: command not found and systemctl: command not found by checking your distro, PID 1 and PATH, then using the right package or service tool.

CloudSat team November 18, 2026 6 min read

`command not found` means the shell searched every directory listed in `PATH` and found no program with that name. When the program is `apt` or `systemctl`, the system is rarely broken. Far more often it is a different system from the one the tutorial assumed: another distribution family, a container, WSL, or a minimal image. Three quick checks tell you which case you are in, and each case has a clean fix.

## Start with three checks

```bash
cat /etc/os-release
ps -p 1 -o comm=
echo "$PATH"
```

- `/etc/os-release` names the distribution. The `ID` and `ID_LIKE` lines tell you its family: `debian`, `ubuntu`, `rhel`, `fedora`, `suse`, `arch` or `alpine`.
- `ps -p 1` prints the name of process 1, the first program the kernel started. On a normal server it is `systemd`. In a container it is usually your application, a shell or a small init such as `tini`.
- `PATH` should contain at least `/usr/local/bin`, `/usr/bin` and `/bin`, plus the `sbin` directories for root.

## apt: command not found

### You are not on Debian or Ubuntu

`apt` is the package manager of the Debian family only. Every other family has its own, and that one is already installed:

| Family (from os-release) | Package manager | Example |
| --- | --- | --- |
| Debian, Ubuntu, Linux Mint | `apt` | `sudo apt install nginx` |
| RHEL, AlmaLinux, Rocky Linux, Fedora, CentOS Stream | `dnf` | `sudo dnf install nginx` |
| openSUSE, SLES | `zypper` | `sudo zypper install nginx` |
| Arch Linux | `pacman` | `sudo pacman -S nginx` |
| Alpine Linux | `apk` | `apk add nginx` (as root) |
| Gentoo | `emerge` | `sudo emerge --ask www-servers/nginx` |
| FreeBSD (not Linux) | `pkg` | `pkg install nginx` (as root) |

On RHEL 8 and later, `yum` still works as an alias for `dnf`. Do not try to install apt on an RPM-based system. Two package managers writing to one system lose track of each other's files and dependencies, and the result is worse than the original error. Translate the tutorial's package names instead: they often differ between families, so search first with `dnf search`, `zypper search` or `apk search`.

### You are inside a container

Container images strip out what their purpose does not need. Debian and Ubuntu images include `apt`, Alpine images use `apk`, and distroless or `scratch` images contain no package manager at all. For those, change the Dockerfile and rebuild instead of patching a running container. When you do install packages in a Debian-based image, use `apt-get`, whose command-line interface is stable for scripts (`apt` warns that its own is not):

```dockerfile
RUN apt-get update \
 && apt-get install -y --no-install-recommends curl ca-certificates \
 && rm -rf /var/lib/apt/lists/*
```

### PATH is broken

If the system is Debian or Ubuntu, test the binary directly:

```bash
ls -l /usr/bin/apt
/usr/bin/apt --version
```

If that works, the program is fine and `PATH` is not. Restore a sane value for the current session, then find the line that broke it in `~/.bashrc`, `~/.profile` or `/etc/environment`:

```bash
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
hash -r
```

`hash -r` clears the shell's memory of where commands used to be. If the error only appears with `sudo`, look at the `secure_path` line in the sudoers file, which sudo uses instead of your `PATH`; edit it only with `sudo visudo`.

### apt really is missing

This is rare and usually self-inflicted: someone removed the `apt` package, which also takes `apt-get` with it. `dpkg` is normally still there. Download the `apt` package (and `libapt-pkg` if dpkg asks for it) matching your exact release from the official Debian or Ubuntu archive, copy it to the server and install it with `sudo dpkg -i apt_*.deb`. If `dpkg` is gone too, restoring from a backup or reinstalling is faster than repair.

## systemctl: command not found

`systemctl` only works where systemd is the init system, running as process 1. The same root cause also produces two close cousins of the error, printed when the binary exists but systemd is not running:

```text
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
```

### In a Docker or Podman container

A container runs your application as process 1, not systemd, so there is nothing for `systemctl` to talk to. That is by design. Run the service in the foreground as the container's main command (for example `nginx -g 'daemon off;'`), use one container per service, and let the container engine's restart policy do what systemd would have done. Installing systemd inside an ordinary container to make tutorials work creates more problems than it solves.

### In WSL

WSL 2 supports systemd, but it must be switched on per distribution, with WSL version 0.67.6 or later (check with `wsl --version` in PowerShell). Inside the distribution, add this to `/etc/wsl.conf`:

```ini
[boot]
systemd=true
```

Then run `wsl --shutdown` from PowerShell and open the distribution again. `ps -p 1 -o comm=` should now print `systemd`.

### On a distribution without systemd

Some distributions use another init system by design. Use its own tools:

| Distribution | Init system | Start a service | Start at boot |
| --- | --- | --- | --- |
| Alpine Linux | OpenRC | `rc-service nginx start` | `rc-update add nginx default` |
| Gentoo (OpenRC profile) | OpenRC | `rc-service nginx start` | `rc-update add nginx default` |
| Devuan | sysvinit by default | `service nginx start` | `update-rc.d nginx defaults` |
| Void Linux | runit | `sv up nginx` | `ln -s /etc/sv/nginx /var/service/` |
| FreeBSD | rc.d | `service nginx start` | `sysrc nginx_enable=YES` |

The `service` command is the most portable habit. On Debian-family systems it hands off to `systemctl` when systemd is running and falls back to the scripts in `/etc/init.d/` when it is not, which is why `service` sometimes works where `systemctl` fails.

### systemd runs, but systemctl is not found

If `ps -p 1` says `systemd` and the command still fails, `PATH` is the problem again: `systemctl` lives in `/usr/bin` on current distributions. Run `/usr/bin/systemctl status` to confirm, then fix `PATH` as shown above. Scripts started by cron or other tools often run with a minimal `PATH`, so use full paths in them.

## Find which package provides a command

When a tutorial uses a tool you do not have, ask the package manager which package ships it:

```bash
sudo apt install apt-file && sudo apt-file update && apt-file search bin/htop
dnf provides '*/bin/htop'
sudo pacman -Fy && pacman -F htop
apk search cmd:htop
```

On Ubuntu, the `command-not-found` helper already suggests the package in the error message itself, so read the full output before searching.

## FAQ

### Can I install apt on AlmaLinux, Rocky Linux or Fedora?

You should not. Use `dnf`, which those systems are built around. Most software has an RPM package or an official dnf repository, and package names are easy to look up with `dnf search`.

### How do apt and apt-get differ?

They share the same engine and repositories. `apt` has friendlier output for people typing commands; `apt-get` keeps a stable interface, which makes it the right choice in scripts and Dockerfiles.

### How do I check which init system a server uses?

Run `ps -p 1 -o comm=`. It prints `systemd`, `init` (sysvinit, OpenRC and some others), `runit`, or the name of a container's main process. On systemd machines, `systemctl --version` also shows the systemd release.

**Run it on CloudSat.** Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. [See plans](https://cloudsat.io/plans) or [deploy a server](https://dash.cloudsat.io/console/deploy).

## Keep reading

[All guides in Linux](https://cloudsat.io/learn/topic/linux)

- [Check the OS and kernel version on Linux and Windows](https://cloudsat.io/learn/check-os-and-kernel-version): Linux Check the OS and kernel version on Linux and Windows 6 min read
- [Keep Linux processes running after logout: nohup and beyond](https://cloudsat.io/learn/keep-linux-processes-running-after-logout): Linux Keep Linux processes running after logout: nohup and beyond 6 min read
- [Delete directories in Linux safely: rmdir, rm -r and find](https://cloudsat.io/learn/delete-directories-in-linux-safely): Linux Delete directories in Linux safely: rmdir, rm -r and find 6 min read
- [List running services on Linux and audit what should run](https://cloudsat.io/learn/list-and-audit-services-with-systemctl): Linux List running services on Linux and audit what should run 7 min read
