Skip to content

How to Fix Command Not Found on Ubuntu, Including apt-get

Updated 5 min read

Updated: 17 October 2026 · Applies to: Ubuntu 26.04 and 24.04 (tested with command-not-found 23.04, sudo-rs 0.2.13 and sudo 1.9), Debian 13, AlmaLinux 10.2, Rocky Linux 9.8, Fedora 44, openSUSE Tumbleweed, Arch Linux, Alpine 3.24

On Ubuntu, command not found means the shell found no program with that name in any folder listed in your PATH. Most of the time the package is simply not installed, and Ubuntu tells you which one to install, for example sudo apt install htop. If the program is installed, your PATH (or sudo's) does not include its folder. And if apt-get itself is not found, the system is not Debian or Ubuntu: it uses dnf, zypper, pacman or apk instead.

1. Read what Ubuntu suggests

Ubuntu's command-not-found helper looks up the missing command in the package lists. Lab example from our Ubuntu 26.04 test container (Ubuntu 24.04 printed the same):

$ htop
Command 'htop' not found, but can be installed with:
sudo apt install htop

$ python
Command 'python' not found, did you mean:
  command 'python3' from deb python3
  command 'python' from deb python-is-python3

The same check for a user outside the sudo group:

$ ifconfig
Command 'ifconfig' not found, but can be installed with:
apt install net-tools
Please ask your administrator.
  1. Install the package it names, for example sudo apt install htop. The package name can differ from the command: ifconfig and netstat come from net-tools.
  2. For "did you mean", use the suggested command (python3) or install the package that adds the old name.
  3. If you only get foobarbaz: command not found with no suggestion, no Ubuntu package provides that command: check the spelling, or install the program from its vendor.

As root the suggestion has no sudo. Minimal installs and container images leave the helper out, so you get only the plain bash: htop: command not found. To add it, run sudo apt install command-not-found followed by sudo apt update.

2. Installed, but still "command not found"

First check where the shell looks:

type apt-get        # apt-get is /usr/bin/apt-get
echo $PATH
  • Debian, normal user: Debian 13 gives normal users a PATH without /usr/sbin (/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games in our test), so admin tools such as useradd report bash: useradd: command not found although /usr/sbin/useradd exists. Run them with sudo, or become root with su - (with the dash). Plain su kept the user's PATH in our test; su - set /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin.
  • Every command fails, even ls: the PATH was overwritten, usually by a line such as export PATH=/opt/myapp/bin in ~/.bashrc or ~/.profile. Restore it for the current session, then fix that line so it appends instead of replacing:
    export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    # correct form in ~/.bashrc:
    export PATH="$PATH:/opt/myapp/bin"
    More in how to set PATH permanently.
  • Works without sudo, fails with it: sudo ignores your PATH and uses secure_path from /etc/sudoers. Ubuntu 26.04 (sudo-rs) says sudo: 'myapp': command not found; Ubuntu 24.04 (classic sudo) says sudo: htop: command not found. Give the full path: sudo /opt/myapp/bin/myapp.
  • A script in the current folder: hello.sh gives command not found, because the current folder is not in PATH. Run ./hello.sh.

3. apt-get: command not found

apt and apt-get exist only on Debian and the systems built on it (Ubuntu, Kali and others). Check which system you are on:

cat /etc/os-release

These are the messages we got for apt-get install htop on other systems (bash adds line N: when the command runs from a script):

bash: apt-get: command not found      # AlmaLinux 10.2, Rocky Linux 9.8, Fedora 44, openSUSE Tumbleweed, Arch Linux
sh: apt-get: not found                # Alpine Linux 3.24 (common in Docker images)
zsh:1: command not found: apt-get     # zsh, the default shell on macOS

Use the package manager of that system instead:

  • AlmaLinux, Rocky Linux, RHEL, Fedora: sudo dnf install htop. yum still works: it points to dnf-3 on AlmaLinux 10 and Rocky Linux 9, and to dnf5 on Fedora 44.
  • openSUSE and SUSE Linux Enterprise: sudo zypper install htop
  • Arch Linux: sudo pacman -S htop
  • Alpine Linux: apk add htop. In a Dockerfile FROM alpine, write RUN apk add --no-cache PACKAGE instead of apt-get install.
  • macOS: there is no apt. According to Homebrew, its package manager installs software with brew install PACKAGE.
  • Windows: apt works only inside WSL. According to Microsoft, wsl --install in an administrator PowerShell installs Ubuntu by default.

Package names also differ between families: the Apache web server is apache2 on Debian and Ubuntu but httpd on AlmaLinux and Rocky Linux. Search first with apt search, dnf search or zypper search. A script written for Ubuntu needs its apt-get lines and package names changed before it runs on AlmaLinux.

4. apt-get missing on Debian or Ubuntu

  1. Check that the file exists: ls -l /usr/bin/apt-get. If it does, the problem is PATH (section 2).
  2. If it is gone, apt was removed. Download the apt package for your exact release from packages.ubuntu.com or packages.debian.org and install it with sudo dpkg -i apt_*.deb.
  3. Some container images ship without any package manager on purpose (distroless images, for example). Build from a debian or ubuntu image if you need apt.

Related: systemctl: command not found on Mac, WSL, Docker and Alpine, add-apt-repository: command not found and netstat: command not found.

Official documentation: apt-get manual (Ubuntu) and Install WSL (Microsoft).

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Linux server management

hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.

Was this answer helpful?

Still stuck? Open a ticket