Kali Linux

How to Fix “Unable to Locate Package” Error in Kali Linux

Kali Linux is an open-source free Debian Linux distribution that is universally utilized in the IT and Cybersecurity world. For auditing security and testing purposes, the users are required to download and install different packages. It offers hundreds of packages and tools for different purposes such as security research, testing, computer forensics, vulnerability management, and many more.

Sometimes, installing the package or tool in Kali Linux may become buggy due to the “Unable to locate package” error. Whenever the user tries to install any package, it shows “E: Unable to locate package <package-name>” as shown below:

This blog will demonstrate:

What are the Reasons Behind the “Unable to Locate Package” Error in Kali Linux?

The “Unable to Locate Package” error usually occurs due to a slow internet connection, outdated repository, or mistakenly spelled wrong package name, the package may not exist in the repository or sometimes, Kali Linux fails to access the source from where the package can be downloaded and installed. These problems must be addressed on time for cybersecurity professionals and trainers.

How to Fix “Unable to Locate Package” Error in Kali Linux?

To resolve the Kali Linux “Unable to locate package” error, first, make sure the package that you need to install exists in the repository. Next, make sure if you have spelled the package name correctly and do you have a good internet connection. After taking all measurements, if the stated error persists, follow the below-listed method to fix the error:

Method 1: Resolve the “Unable to Locate Package” by Updating the Repository

To tackle the “unable to locate package <package-name>” error, first, launch the terminal and run the “sudo apt search <package-name>” command to file if the searched package exists in the repository or not. Then, update the repository. For illustration, follow the below given procedure.

Step 1: Launch Terminal

First launch the Kali terminal by either clicking on the “Terminal” icon from the Task menu or pressing the “CTRL+ALT+T” key:

Step 2: Search Repository Packages

Next, search for the package that you want to install from the repository. For this purpose, utilize the “apt search <package-name>” command:

apt search checkinstall

To view all packages from the APT repository, utilize the “apt search .” command:

apt search .


Step 3: Update the Repository

If the package is present in the repository and still user faces the “Unable to locate package” error, update the APT repository using the “apt update” command with “sudo” privileges:

sudo apt update

Try to download the package and check if the stated error is resolved or not.

Note: If the user faces an error while updating the repository then it means Kali is unable to access the correct source to download the package and is shown the “unable to locate package” error. Move ahead toward the second method to fix the stated issue.

Method 2: Resolve the “Unable to Locate Package” by Updating the “sources.list” File

Like all other distributions, Kali Linux requires the source or repository to download and install the tools and packages. However, sometimes, the Kali Linux “sources.list” file that contains sources to download packages may be corrupted or contain an outdated source. Due to this, the user may face an “unable to locate package” error while installing the package. To fix the stated issue, utilize the following demonstration.

Step 1: Navigate to “/etc/apt/” Directory

First, navigate to the “/etc/apt/” directory through the “cd” command:

cd /etc/apt/

Step 2: Create the Backup of “sources.list” File

Before making changes to the “sources.list” file, make a backup of the file. For this purpose, utilize the “cp” command to copy the content of the “sources.list” file into a new file named “sources.list.backup”. The given command needs to be executed with “sudo” user privileges:

sudo cp sources.list sources.list.backup

For confirmation, list down the file using “ls”:

ls

Here, we have effectively created the backup of the “sources.list” file:

Step 3: Open the “sources.list” File

Next, open the “sources.list” file in any text editor such as vim or nano. For instance, we have opened the file in the nano editor:

sudo nano sources.list

Completely clear the file by removing its content:

Step 4: Add Source Path to Download Packages

After clearing the file, paste the below-given source into the file. This is the official Kali source from where the user can install the packages:

deb http://http.kali.org/kali kali-rolling main contrib non-free non-free-firmware

After pasting the source, save the changes using “CTRL+S” and leave the editor through the “CTRL+X” key.

Step 5: Update the Repository

Now, update the repository to implement the changes in Kali Linux through the “sudo apt update” command:

sudo apt update

Step 6: Install the Package

Install the required package through the “sudo apt install <package>” command:

sudo apt install checkinstall

Here, from the given result, you can see we have effectively resolved the “unable to locate package” error:

Alternatively, the user can directly paste the authorized and correct installation source to the “sources.list” file in the single command. For this purpose, go through the below-mentioned command:

echo "deb http://http.kali.org/kali kali-rolling main contrib non-free non-free-firmware" | sudo tee /etc/apt/sources.list

We have covered the methods to tackle the Kali Linux “unable to locate package” error.

Conclusion

To fix the “unable to locate package” error, make sure the user has a good internet connection, and the package you need to install exists in the repository. If the repository is outdated, the user may face a stated error. To fix the error, update the repository using the “sudo apt update” command. Sometimes, Kali Linux may not be able to access the source to download the package. For this purpose, open the “/etc/apt/sources.list” file and add the source path or URL in the file. This post has covered the techniques to tackle the Kali Linux “Unable to locate package” error.

About the author

Rafia Zafar

I am graduated in computer science. I am a junior technical author here and passionate about Programming and learning new technologies. I have worked in JAVA, HTML 5, CSS3, Bootstrap, and PHP.