unable-to-locate-package-error-fix

How to Fix “Unable to locate package” error in Ubuntu or Debian distros – (6 Solutions in 2021}

This post is for all Linux lovers and newbies. If you are getting an “Unable to locate package” error and want to resolve it. You have landed on the right page. When I started my Linux journey many years ago, I also got this error in Ubuntu.

There may be many reasons to encounter this error like the incorrect package name, Absolute path, package not available in repo and more. We will see all the related issues and solution individually.

I am sure if you will follow this post step by step, You will be able to resolve the following errors. This post specifies Ubuntu but the solutions also apply to other Debian distros –

  • Unable to locate package
  • Unable to locate package ubuntu
  • E unable to locate package Kali Linux
  • Unable to locate package Debian
  • E: unable to locate package update
  • Unable to locate package pip
  • Unable to locate package nodejs
  • Unable to locate package python

All the above-mentioned error may occur due to different scenarios. I will replicate these errors and then give you a solution for easy understanding.

Below mentioned are Possible Causes for most of the errors

  • The package name is incorrect or case sensitive problem
  • Providing a file name instead of the package name
  • Not providing a full path to your downloaded .deb package
  • Forgot to update the repository, after a fresh Ubuntu installation
  • The package is not available for your Ubuntu version in the official repository
  • Your Ubuntu or Debian distro reached the end of life
  • The apt command syntax is not correct
  • /etc/apt/sources.list is missing or corrupted

Let’s deep dive and find solution to these possible cause –

Solution 1 – How to Fix “Unable to locate package in Ubuntu” error due to incorrect package name

It may sound silly, but yes, I still do this mistake very frequently. Sometimes I type the wrong package name while installing packages in my Ubuntu system.

I have no doubt about your intelligence, but typing error may happen with anyone. Also If you are a newbie, keep in mind that Linux is case sensitive.

These are the very common mistakes happen during package installation –

  • The package name is not correct or not known
  • Lowercase or upper case issue in the package name
  • Not providing specific or complete package name with version

Let me show you this with an example –

I want to install Java (version 11) in my Ubuntu 20.04 and I am not aware of the package name. If I will assume and try to install it with the name “java”, it won’t work.

I am getting “unable to locate package java“. Because it doesn’t exist with this name.

$ sudo apt install java
E-unable-to-locate-package-java

The name of Java package starts with “openjdk” in real.

How to find package in Ubuntu repository, if exact package name not known

To find out the correct name of your package, you can follow these simple steps. It will make sure, there is no issue related to package name, lower or uppercase and even versions.

Step1.1 – Visit Ubuntu package archive site and select your Ubuntu distro version

Visit https://packages.ubuntu.com/ and search for your package.

I am using Ubuntu 20.04. I will select focal (20.04LTS) from the list. You need to select your distro. You can check your Ubuntu version to get these details.

manual-package-search-in-ubuntu-repository

Step1.2 – Choose your package category

On this page, You will get a lot of sections like Administration utilities, Database, Development etc. to make your search easy.

Choose your section to deep down one more level. For example, I will select Java from the section –

Choose-your-package-java

Step1.2 – Search for your package from the subsection list

Search for your required package name. For example, I will look out for Java development kit version 11.

So I gave “development kit” in the search box and reached for the package openjdk-11-jdk.

You may need to do some hit and trial or manual search to reach your package, when you are really clueless about your package name.

select-openjdk-from-repo-subsection

Step1.3 – Install your required package using apt command

Now I know the correct name and package version i.e. openjdk-11-jdk. I will be able to install it without any issue.

$ sudo apt install openjdk-11-jdk
unable-to-locate-package-java-error-fixed

Solution 2 – Provide an absolute package (.deb) path, for offline package installation

In case your package is not available in the official Ubuntu repository and you have downloaded (.deb) package from the third-party site.

You are getting “unable to locate package” while installing it offline. It means you are not giving absolute path to your .deb package file.

Let me explain you with an example –

Google chrome browser is not part of Ubuntu official repository. So I downloaded .deb package of chrome and tried to install it.

Google Chrome “.deb” file exists in my Downloads directory. and if you notice in the image, I am in the same directory. But still, I am getting an “unable to locate package google-chrome-stable_current_amd64.deb” error.

$ sudo apt-get install google-chrome-stable_current_amd64.deb
Unable-to-locate-package-error-due-to-absolute-path

Now I will just provide absolute path to .deb package file and it will work like a charm.

$ sudo apt-get install ./google-chrome-stable_current_amd64.deb
Providing-complete-path-fixed-unable-to-locate-package-error

Solution 3 – Update and build local repository cache

You may encounter this scenario if you have installed Ubuntu fresh and trying to update or install packages. Additionally, You are new to the Linux world.

Let me highlight, You must run “apt update” first to build a local cache repository. Otherwise empty cache will not return anything.

Actually, the package manager fetches the metadata of available packages over the network. Then it builds a local cache in the system, to provide a fast result to your package query.

The local cache repository may get stale anytime. So please make a thumb rule. Always update the package repository first and then only install the package. It is applicable to all Debian distros.

$ sudo apt update

Then install the required package.

$ sudo apt install "your-package-name"
update-cache-repository-to-fix-unable-to-locate-package-error

Solution 4 – “Unable to locate package” in Ubuntu official repository

There are cases, when you try to install Ubuntu package. It may or may not exist in repository.

So first, we should search manually and confirm about the package availability, then we can go with external or third party repositories.

How to search package in Ubuntu repository using CLI and GUI

There are two ways to verify it –

  1. Find a package in the Ubuntu repository using GUI
  2. To find a package using the apt-cache command in terminal

Step 4.1 – Search for a package in Ubuntu repository {GUI}

  • Open terminal <Ctrl +Alt + T> in Ubuntu and find out your distro code name using “lsb_release” command.

For example, I am using Ubuntu 20.04, with code name “Focal“.

dev@ubuntu:~/Desktop$ lsb_release -c
 Codename:    focal
check-codename-ubuntu
  • Visit Ubuntu repository page > Scroll down to search section
  • Fill “package name” in the keyword and select “Distribution“. In my case, it will be focal.
  • Hit the “Search” button.

For example, I will look for TeamViewer package. It’s used to connect a system remotely over the Internet or intranet.

search-for-your-package-in-ubuntu-repository

So I was unable to find it in Ubuntu repository –

download-install-package-third-party-if-not-with-ubuntu-repository

Step 4.2 (Optional) – Search for a package in Ubuntu repository {CLI}

If you don’t to leave your terminal and want to search package in Ubuntu repository using CLI. Follow these steps –

Run this command in terminal –

$ sudo apt-cache search "your-package-name"
or
$ sudo apt-cache search . | grep -i "package-name"

For example –

$ sudo apt-cache search teamviewer
or 
$ sudo apt-cache searcch . | grep -i teamviewer

If you are not getting any result of this search query, it means the package doesn’t exist in the Ubuntu repository. Now either you need to download and install it using a third-party site or repository (PPA).

You can check out this article, to see the different ways to install packages in Ubuntu and TeamViewer installation.

Solution 5 – Your Ubuntu or Debian distro reached the end of life

You can encounter “unable to locate package error” in case your Ubuntu or Debian distro is legacy or very old.

Ubuntu or any Linux vendor, don’t provide support or latest package release for end of life distros.

For example, Ubuntu 14.04 is already end of life and Ubuntu 16.04 will obsolete in April 2021.

Ubuntu end of life release

So you must plan for upgrade, in case you are still using these old versions and want to avoid package related issues.

Solution 6 – /etc/apt/sources.list is missing or corrupted

The “sources.list” file contains all your Ubuntu and third party repository URLs. So whenever you run the apt command to install any package. It checks within this file and gives result.

You may encounter “E: unable to locate package“, if /etc/apt/sources.list file is missing or corrupt.

One of the reason of corruption is incorrect editing of sources.list file.

I have deleted my sources.list file just to replicate the issue and I started getting “unable to locate package” error.

For example, if I try to install any package like python, I am getting error as shown in output –

dev@ubuntu:~$ sudo apt install python
Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Unable to locate package python

and same for nodejs package installation. So it confirms, that issue is with sources.list file because I am unable to install any package.

dev@ubuntu:~$ sudo apt install nodejs
Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Unable to locate package nodejs
unable-to-locate-package-error-due-to-sources-list-file-corrupt

How to Fix /etc/apt/sources.list is missing or corrupted

Follow these easy instructions to rebuild sources.list file again.

Step 6.1 – Delete existing corrupt /etc/apt/sources.list file, if it exists.

If your sources.list file is corrupt, then you need to delete it first. If it’s already missing, then you can skip this step.

$ sudo rm -rf /etc/apt/sources.list

Step 6.2 – Regenerate sources.list file

Run following command –

$ sudo software-properties-gtk

You will get the Software and Updates window. Select all the checkboxes as shown in the image. Also, select the “main server” in Download from the dropdown.

Regenerate-sources-list-file

Click Close.

You will get a warning to reload or refresh the repository cache. Select <reload> to generate sources.list file and apt-cache. it’s like running apt-get update command from the terminal.

refresh-apt-cache

It will take few seconds to refresh software cache.

Refresh-software-cache-ubuntu

You can later add third party repository as needed.

Now you can easily install your nodejs or python package. You will not get “unable to locate package nodejs” error anymore.

unable-to-locate-package-fixed

Video tutorial

Watch this informative video tutorial for 6 solutions on “How to fix “unable to locate package” error in Ubuntu. This is really helpful if you don’t like reading or have any doubts about the steps.

x
How to Fix "unable to locate package error" in Ubuntu video
Conclusion

If you are getting this very common “unable to locate package” error in Ubuntu or other Distros like Linux Mint. I hope, resolving this error would be a cakewalk for you after reading this post.

If you find any scenario, while using Linux, which is not covered in this post. Let me know through your comments. I will try to add that also in this post.

If you find it useful, Please share it with your friends on social media.

Happy learning..