Fix apt-get command not found – everything you need to know (Updated 2022)

APT (Advanced Packaging Tool) is an advanced package management system used by Debian Linux and Linux distributions based on Debian (such as Ubuntu). APT automatically configures, compiles and installs software from many sources such as internet, LAN server, or cdrom. It can greatly simplify process of installing and removing software on Linux system.

APT is not just a specific command, but also a package management tool set composed of a set of commands. The most commonly used APT commands include apt-get and apt-cache.

Sometimes, you will encounter “apt-get : command not found” error when you try to run apt-get commands either on your own Linux machine or server. This article is going to help you understand a few reasons why it may happen and how to fix it quickly.

What is apt-get command?

APT is a command line (CLI) program in Linux that allows users to install, update, and remove software from their computer. This program is designed to be user-friendly, which it makes it easy for users to keep their software up-to-date. apt-get is the primary command of APT, which can perform most of its functionality.

Below are several handy apt-get commands you should always remember:

  • sudo apt-get install X (install a package)
  • sudo apt-get remove (remove a package)
  • sudo apt-get update (update a package)
  • sudo apt-get upgrade (for upgrading a package)
  • apt-get help (to know more about a command )

apt-get doesn’t support your Linux distribution

At any moment, there are around a thousand Linux distribution (or Linux distro) exist. They can be configured and optimized for various devices (desktops, laptops, servers, tablets, etc). They can be packaged in a way that suit a community. They can even be developed exclusively to use on an online service (Amazon Linux AMI).

Each Linux distribution has its own preference of standard package manager. While Debian and Ubuntu default choice for package manager is apt, Fedora/RHEL family choose yum and dnf.

Below is a list of the most popular distribution and their package manager of choice.

Major distributionPackage management systemPackage manager
Red Hat LinuxRPM-basedyum/dnf
FedoraRPM-basedyum/dnf
CentOSRPM-basedyum/dnf
Amazon LinuxRPM-basedyum/dnf
openSUSERPM-basedzypper (CLI)/YaST (GUI)
DebianDEB-basedapt/apt-get
UbuntuDEB-basedapt/apt-get
Kali LinuxDEB-basedapt/apt-get
Arch LinuxPacman-basedpacman
GentooPortage-basedportage (emerge)
SlackwareSlackPKGpkgtool/slackpkg

As you can see from the table, only Debian and Ubuntu based distribution use apt by default.

You can check whether your distribution include apt under the hood or not by printing out details about the OS with cat /etc/*-release command. Below is the typical output you would get out of cat /etc/*-release.

$ cat /etc/*-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=20.04 DISTRIB_CODENAME=focal DISTRIB_DESCRIPTION="Ubuntu 20.04.3 LTS" NAME="Ubuntu" VERSION="20.04.3 LTS (Focal Fossa)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 20.04.3 LTS" VERSION_ID="20.04" HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" VERSION_CODENAME=focal UBUNTU_CODENAME=focal

Alternatively, you can use one of a few other method to find the name and version number of your Linux distro.

Side note: If you’re copying terminal commands from a guide, you may have used the commands built for another Linux distribution. We suggest finding another suitable tutorial which was demonstrated on your specific Linux distro version to avoid encountering strange error.

Better yet, you can use AppImage, a new packaging format which allows applications to run as portable executable files instead of relying on the old, clunky apt. However, you may still need apt, since no other package manager is able to catch up with it in terms of number of packages and system stability.

apt-get: command not found in AWS

“apt-get : command not found” is a common issue for AWS users who are running Amazon Linux images in their servers. The fact is, Amazon Linux is based on CentOS, which in turn based in RHEL. The RHEL distro family prefer yum over apt as the preferred package manager.

Most of the time, in order to install a common piece of software, you can try replacing apt or apt-get with yum to see if it succeed. For example, instead of apt install python3, you can try to run yum install python3. It should work most of the time.

The reason behind this trick is most common packages are named uniformly across different repository, and yum and apt syntax is strangely similar, which makes it easy to substitute one for another.

In case the new command does not install anything, you can always look for tutorials that was made for Fedora or CentOS.

apt-get: command not found in GCP/Google Cloud

Users have reported across online forums that they haven’t been able to use apt properly in Google Cloud Platform virtual machines.

In this case, GCP isn’t the one to blame. If you’ve chosen Ubuntu as the preferred image upon VM creation, you can definitely use apt without any further steps. There are a few possible reasons that can explain this.

  • You could have ticked Containers check-box in Cloud Console while creating the instance. Once the Containers checkbox is activated in instance creation dialog, the boot disk selection will be overridden with Container-Optimized OS, which is a slimmed-down version of Debian/Ubuntu family. apt have been cut out of that container-optimized OS to reduce system overhead as much as possible.
  • You’ve selected something else instead of Debian/Ubuntu images.
  • You’re in some kind of a nested environment inside the OS, which somehow does not have apt preinstalled.
Container image check-box in Google Cloud Console

Check apt path for its binary

“apt-get : command not found” indicates that the system is not able to access apt-get at its path. The logical way to solve this would be manually verify that the path is in place.

Type the following command in the terminal to see where the system expect apt-get binary would be :

locate apt-get
Code language: JavaScript (javascript)

The following output should look like the following image or contain this string : /usr/bin/apt-get

image-20210113083857048

If the command returns no output, then you have no “apt” package installed.

You will have to install it manually using a .deb file.

Manually reinstall APT using its DEB installer

In order to manually reinstall APT using its DEB installer, you need to grab the corresponding .deb package that was compiled specifically for your OS version.

If you’re using Ubuntu (or any distro based on Ubuntu), go to the Ubuntu Archive Mirror to look for pre-compiled binaries of apt.

Ubuntu mirror archive
  • Then, go to /pool/main/a/apt/ and you’ll see a bunch of files named apt. You would have to download the appropriate DEB file (ending with .deb). Download amd64 file if you’re running Ubuntu 64-bit and i386 file if you’re running the 32-bit version.
select apt deb file
  • Once it finishes downloading, you can install the downloaded file by running dpkg. Suppose the file is named apt_2.1.17_amd64.deb, the command should look like below
sudo dpkg -i /path/to/<span style="background-color: inherit; font-family: inherit; font-size: inherit; white-space: pre-wrap; color: inherit;">apt_2.1.17_amd64.deb</span>
Code language: HTML, XML (xml)

Remember to replace the /path/to/apt_2.1.17_amd64.deb with the path of the file you’ve just downloaded.

Fix apt-get command not found on macOS

macOS, by default, doesn’t use APT package manager. In fact, the OS doesn’t have a default package manager at all. However, there is a hugely popular apt-get alternative for macOS called Homebrew.

Below is how you would install Homebrew on macOS.

  • First, press the Command + Space key combination to open the Spotlight. Type in “terminal” without the double quotes and hit Enter.
  • Then, you have to install XCode by running the following command :
xcode-select --install
  • Once XCode is successfully installed, you can install Homebrew by running the following one-line command
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Code language: JavaScript (javascript)
  • Please do note that some of the guides you found online may use ruby instead of /bin/bash. Previously, Homebrew installer relies on Ruby as a prerequisites, but now it’s been rewritten from scratch and use the built-in bash shell included in macOS. On modern macOS versions, you may encounter “The default interactive shell is now zsh” message, we have a guide on how to fix it that you may want to check out.
  • Now wait for the installation to finish. You may be prompted for your password during the process.

Sometimes, the Homebrew installer stuck up somewhere and left a corrupted installation. In that case, you may want to read our guide on possible fixes for “brew: command not found”.

The command to install a package with Homebrew is similar to its APT counterpart.

brew install <package name>
Code language: HTML, XML (xml)

Last resort : Reinstall the OS

If you’ve followed the two method above with no luck, then the fastest option in this situation is reinstall the operating system. On a server, you can simply re-imaging the server to have a fresh start.

Remember to backup your data and settings before the reinstall. If you didn’t have a tool of your choice to do that, we recommend rclone, a robust and battle-tested solution preferred by open-source community. We did have a guide on how to install rclone on Ubuntu and a few rclone examples to get you started.

Conclusion

We hope that this tutorial helps you solve the problem effectively and quickly. If you spot any error in the article, or have a suggestion, please let us know via the comment section below. You might also want to check out our guide on fixing other common apt errors, such as “Unable to lock the administration directory (/var/lib/dpkg/)”, apt-get: Could not resolve archive.ubuntu.com.

FAQ

  1. Possible causes of apt: command not found error?

    The apt: command not found error message may be caused by one of the following reasons:
    1. Not currently using Debian/Ubuntu or their derivarives.
    2. Running a slimmed down version of Debian/Ubuntu in which apt has been removed.
    3. apt binary has been accidentally deleted.

  2. Which is the simplest solution to apt-get command not found?

    Simply reinstall apt using appropriate binaries downloaded from http://us.archive.ubuntu.com/ubuntu/ by running dpkg -i apt_installer.deb.

  3. How to debug apt command not found?

    You can try checking apt logs at /var/log/apt or system logs by running journalctl -u

Click to rate this post!
[Total: 71 Average: 5]

1 thought on “Fix apt-get command not found – everything you need to know (Updated 2022)”

  1. Thanks a lot. You saved me countless of painful time.

    Reply

Leave a Comment