How to fix 'E : unable to locate package' error on Ubuntu

Endrit Qerreti

Endrit Qerreti

Are you getting the error "E: Unable to locate package" when trying to install a package on Ubuntu?

This error happens for various reasons.

You will encounter this error, when trying to install a package that it's not found on Ubuntu repositories.

To give you an example, teamviewer it's not on Ubuntu repositories, so if we try to install teamviewer using the apt install command, we would get the error "Unable to locate package teamviewer" as shown in the image below

Another reason could be spelling mistakes, even if that package is available on Ubuntu repositories, if the name of the package it's not spelled correctly then apt won't be able to find and install that package.

For example, trying to install firefox browser

As you can see, we got the same error because firefox it's not spelled correctly.

We showed you two example why this error happens. However, the difference between these two errors is that, the first error happened because the package wasn't found on Ubuntu repositories but the name of package was spelled correctly.

The second error happened, because of spelling mistakes, we were trying to install firefox, using firefoxx as package name, but the package is available on Ubuntu repository.

Even though we got the same error for both examples, the reasons are not.

Apt won't tell you the exact reason why the package wasn't found, so you have to check and verify if the package that you are looking to install, it's actually a valid package on Ubuntu repositories. So, to troubleshoot these issues, it is recommended to double check that the package is available on Ubuntu repositories, or any third party repository, and that there are no spelling mistakes.

To check if a package is available on Ubuntu repositories, you can search for a package using the apt search command

To do this, simply open your terminal, and run the command below

apt search <package>

Let's say we want to install firefox, and we want to check if firefox is found on Ubuntu repositories

apt search firefox

As you can see, we got multiple results showing on our terminal based on the keyword that we were searching for.

Now we need to locate firefox before proceeding to install it.

If you get a lot of results of the package that you are searching for, you can search only for the name of the package by using the --names-only argument when searching

apt-cache search --names-only firefox

As you can see, the results are now way more easier to read

You can also use the syntax below to filter results, and show only packages that have the exact keyword that you are searching

We are interested only in the firefox package and not other packages. To do this, run the command below

apt-cache search --names-only ^firefox$

As you can see below, we got the result we were looking for

Conclusion

In this tutorial, you learned what causes the error 'E: unable to locate package' on Ubuntu, and how to fix it.