HomeLinuxHow to Fix “E: Unable to Locate Package” Error on Ubuntu

How to Fix “E: Unable to Locate Package” Error on Ubuntu

When using Ubuntu or any Debian-based Linux distribution, encountering the “E: Unable to Locate Package” error can be frustrating, especially when trying to install software or packages.

apt-get install package_name

Output:

Reading package lists... Done
Building dependency tree      
Reading state information... Done
E: Unable to locate package package_name

This error typically occurs when the package you’re attempting to install cannot be found in the configured repositories. 

Different methods to Fix “E: Unable to Locate Package” Error:

1. Update Package Lists

Before attempting to install any package, it’s essential to update the package lists to ensure you have the latest information about available packages. If the cache does not support the required package, Ubuntu will have difficulty installing both the software and the package.

As a result, we must update the Ubuntu repositories package lists to include new and updated packages and software.

Open the terminal and run the below command.

apt update && sudo apt upgrade -y

2. Check Spelling and Case Sensitivity

Ensure that you have spelled the package name correctly and that the case matches. Package names are case-sensitive, so even a small typo can lead to this error.

For example, If you want to install the package libjpeg-dev, which is a development library for JPEG image format support. However, if you mistakenly type LibJpeg-dev with a capital “L” and incorrect casing, you’ll encounter the “E: Unable to Locate Package” error.

apt install LibJpeg-dev

When you run this command, Ubuntu will not find the package because it’s case-sensitive and the correct package name is libjpeg-dev, not LibJpeg-dev.

To fix the error, ensure that you use the correct spelling and casing for the package name:

apt install libjpeg-dev

3. Enable Additional Repositories

To add the main repositories to your Ubuntu system, you can use the add-apt-repository command with the universe, multiverse, and restricted repositories. These repositories contain a vast collection of software packages that are officially supported by Ubuntu.

Older Ubuntu versions do not have the main repositories by default. Fortunately, this problem does not occur in subsequent versions of Ubuntu (such as Ubuntu 20.04 and Ubuntu 22.04), which are distributed with the main repositories.

If you have an an older version of Ubuntu, you can add the main repositories on Ubuntu by using the commands below.

add-apt-repository main
add-apt-repository universe
add-apt-repository restricted
add-apt-repository multiverse

After running these commands, you should update the package lists using apt update to ensure that the newly added repositories are recognized by the system. Once the update is complete, you can install packages from these repositories using apt install as usual.

4. Check if the package is available for the Ubuntu version

Here, if any of the above solutions didn’t worked, it may be the package you are installing may be not available for your particular Ubuntu version.

To find if the package is available for the current Ubuntu version, you should know information about the current Ubuntu version using the command given below.

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu 
Description: Ubuntu 22.04.1 
LTS Release: 22.04 
Codename: jammy

Here you can see the version of Ubuntu you are currently using.

Now you can check your package is available for your Ubuntu version by visting Ubuntu Packages.

Using the output, you can understand whether the package you are trying to install in the current ubuntu version is available or not. If the particular repository is available, check the name of the repository which it belongs to.

If this package is available in any of the repository given in method 3 and it is unavailable in your ubuntu system, this also shows the error “E: Unable to Locate Package”.

To resolve this, as in method 3, you have to add that particular repository to your Ubuntu.

5. Clear the Package Cache

Sometimes, the package cache might be corrupted, leading to this error. To resolve this, clear the package cache by running

apt clean

6. Try a Different Mirror

In the context of software repositories, a mirror refers to a copy of a repository that is hosted on a different server than the original repository. Mirrors are used to distribute the load of downloading packages and updates across multiple servers, improving download speeds and reducing the load on individual servers.

These mirrors are identical all throughout. In other words, they all host the same exact information. Software downloaded from an Ubuntu server in the United States produces same effects as software downloaded from Japan.

You can change the mirror used by Ubuntu to download packages by editing the /etc/apt/sources.list file.

Follow these steps to try a different mirror:

1. Open a terminal on your Ubuntu system.

2. Edit the sources.list file using a text editor.

vi /etc/apt/sources.list

Inside the text editor, you’ll see lines that begin with deb. These lines specify the repositories (mirrors) from which Ubuntu downloads packages. Each line typically starts with deb, followed by the mirror URL.

3. Locate the line that starts with your current mirror URL. It usually looks like this:

deb http://archive.ubuntu.com/ubuntu/ focal main restricted

4. Replace the current mirror URL with the URL of a different mirror. You can find a list of Ubuntu mirrors on the official archive mirrors website. For example, you might replace http://archive.ubuntu.com/ubuntu/ with http://mirror.example.com/ubuntu/.

5. After saving the changes, update the package lists to fetch packages from the new mirror:

apt update

You can now try installing or updating packages to see if the new mirror is being used:

apt install <package-name>

By following these steps, you can try a different mirror in Ubuntu.

7. Check the activation of the Ubuntu version

If your Ubuntu version is no longer supported or has expired, installing new packages will result in the error “E: Unable to Locate Package”.
To determine the status of the Ubuntu version and to know whether it is supported or not.

hwe-support-status --verbose

Output:-

You are not running a system with a Hardware Enablement Stack. Your system is supported until April 2025.

Conclusion:

By following these steps, you should be able to troubleshoot and resolve the “E: Unable to Locate Package” error on Ubuntu effectively.

Scroll to Top