On this pageStart with three checks
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
cat /etc/os-release
ps -p 1 -o comm=
echo "$PATH"
/etc/os-releasenames the distribution. TheIDandID_LIKElines tell you its family:debian,ubuntu,rhel,fedora,suse,archoralpine.ps -p 1prints the name of process 1, the first program the kernel started. On a normal server it issystemd. In a container it is usually your application, a shell or a small init such astini.PATHshould contain at least/usr/local/bin,/usr/binand/bin, plus thesbindirectories 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):
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:
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:
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:
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:
[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:
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 or deploy a server.




