Linux Commands

How to Fix the “apt command not found” Error

“This article explains how to solve the “apt-get command not found” error in Linux.

It is very important to clarify most users getting this error are not getting a genuine system error, but they are using a Linux distribution with a different packages manager than apt. It is usually caused by a user-side mistake.

In most cases, users facing this message just need to use the proper packages manager for their Linux distribution.

The apt or apt-get package managers are used by Debian-based Linux distributions like Ubuntu.

If you are using a different Linux distribution like CentOS, you need to use the yum packages manager instead of apt. If you are using Fedora, use the dnf packages manager.

SUSE users must use the zypp packages manager.

If you are using a Linux distribution like Debian or Ubuntu and you get the “apt command not found error”, then keep reading below. The first section of this document is for Ubuntu users; instructions for Debian users can be found in the second section.

Fixing the “apt command not found” Error in Ubuntu Linux

In this tutorial, I assume, for some reason, the apt packages manager frontend got removed from your system.

The instructions below describe all steps to install the last apt package release for Ubuntu.

To begin, access this link https://packages.ubuntu.com/ and scroll down the page to find the Search section.

Type apt in the keyword field, select the correct Ubuntu release and press the Search button as pointed by the arrows in the screenshot below.

Scroll down the opening page and press the link to the apt package, as shown in the following image.

Scroll down the opening page. At the bottom, you will find links for each architecture; press the correct one for your system.

To finish downloading apt, press the download link.

Once the package is downloaded, install it using dpkg as shown below. It is important to clarify that 1.6.12ubuntu0.2_amd64 must be replaced with the exact version and architecture you have downloaded.

sudo dpkg -i apt_1.6.12ubuntu0.2_amd64.deb

Test apt again to check if it now works.

If it still does not work, there is probably a problem with the $PATH environment variable.

To confirm it, first check where the apt binary is. You can use the command whereis, as shown in the following example.

whereis apt

As you can see, the binary is under the binaries directory /usr/bin (/usr/bin/apt).

To confirm if the path is included in your $PATH environment variables, use the command echo followed by the environment variable you want to check ($PATH).

echo $PATH

As you can see, each path is separated by a colon. If, in your case, the path /usr/bin is not included, add it using the export command as shown in the following image, then test apt again.

export PATH=$PATH:/usr/bin

If, after exporting the path, the apt packages manager works properly, you find the problem. But exporting the path from the command line is only a temporary fix without persistence after a system reboot or session change.

To make this solution permanent, open the .bashrc file inside your home directory using a text editor like nano or vi.

nano .bashrc

At the end of the file, add the following line.

export PATH="$PATH:/usr/bin"

Close the .bashrc file saving changes and update the path environment variable by executing the following command.

source .bashrc

Now the apt command must work.

How to Fix the Error “apt command not found” in Debian Linux

For Debian users to fix this error, first visit the link https://www.debian.org/distrib/packages#search_packages and scroll down to find the Search section.

On the keyword field, type apt, select the correct Debian distribution and press the Search button.

You will be redirected to a page containing a list of packages. Press the apt package link belonging to your Debian version.

Scroll down the opening page and press the correct architecture for your system.

After being redirected to the mirrors page, press any of them to start downloading the package.

In some cases, your browser may prevent you from downloading the package. Allow the package to be downloaded.

Once you get the package using the dpkg packages manager to install it, as shown below. Remember that 2.2.4_amd64 must be replaced with the actual version/architecture you are downloading.

sudo dpkg -i apt_2.2.4_amd64.deb

Now the apt command must work. If it still does not work, there is probably a problem with the $PATH environment variable.

First, check where the apt binary is. You can use the command whereis, as shown in the following example.

whereis apt

As you can see, the binary is under the directory /usr/bin (/usr/bin/apt).

To see if the path is included in your environment variables, use the command echo followed by the environment variable you want to check (In this case, $PATH).

echo $PATH

As you can see, each path is separated by a colon. If, in your case, the path /usr/bin is not included, add it using the export command as shown below, then test apt again.

export PATH=$PATH:/usr/bin

If, after exporting the path, the apt packages manager works, you find the problem. But exporting the path from the command line is only a temporary fix without impact after rebooting or changing the session.

To make this fix permanent open the .bashrc file inside your home directory using a text editor.

nano .bashrc

At the end of the file, add the following line.

export PATH="$PATH:/usr/bin"

Close the .bashrc file saving changes and update the path environment variable by executing the following command.

source .bashrc

That’s all; I hope these steps fix your problem.

Conclusion

The most common cause of this error message is the wrong use of a package manager not compatible with the installed Linux distribution. In most cases, this is a mistake from the user’s side. But if the user is trying to use the apt packages manager correctly in a compatible Linux distribution, installing it or fixing the path, as described in this tutorial, very probably will solve the problem, unless it is not a consequence of a wrong installation or a more serious system failure. All possible solutions previously explained are pretty easy to implement by any Linux user, independently of the expertise level. It only requires using the dpkg packages manager or fixing the path.

Thank you very much for reading this article; I hope it was helpful to solve the problem. Keep following us for additional tips and tutorials.

About the author

David Adams

David Adams is a System Admin and writer that is focused on open source technologies, security software, and computer systems.