357

When I try to install any package through the command line, I get an error.

$ sudo apt-get install <package>
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package <package>

Can anyone help me on this?

6
  • 12
    This is coming up a lot recently because 18.04 Server has universe, multiverse, and backports disabled by default.
    – wjandrea
    Sep 8, 2018 at 22:40
  • 1
    Is there a launchpad issue for improving the helpful hint given when entering a command not installed? (Just hinting that it is in a repository not enabled would be very helpful) Sep 13, 2018 at 16:04
  • This is something I hit a lot when I am building containers, usually with both Docker and Singularity. In Singularity containers you have different BootStrap options, among them being debootstrap and docker. For some reason, if I use debootstrap to start with a base Ubuntu image (e.g. xenial), I hit this error where some packages cannot be found with apt-get. The solution ends up being to switch to the docker BootStrap, then it functions again. May 22, 2019 at 16:21
  • 2
    @Jackalope Then maybe the package name is incorrect or you need to run sudo apt update. Use apt-cache search followed by a search term to search for the correct package name.
    – mchid
    Aug 29, 2019 at 4:37
  • I've done those things. I've triple-checked the name of the package (libsdl2-2.0-0), & verified availability with apt-cache search. I was eventually able to get this package installed by installing the docs, which appears to have installed the package as a dependency.
    – Jack
    Aug 31, 2019 at 18:23

7 Answers 7

229

First, check if the package actually does exist:

  1. Go to packages.ubuntu.com with a web browser.

  2. Scroll down to "Search package directories"

  3. Enter the package which you're trying to install into the "Keyword" field.

    Enable "Only show exact matches:"

    Change the "Distribution" to the codename of the version of Ubuntu you're using, e.g. focal in Ubuntu 20.04 or it's displayed by lsb_release -sc

    Search package direction. Keyword search box: "unity", with buttons for "Search" and "Reset". Followed by options for "Search on", with "Package names only" selected (with "descriptions" and "Source package names" being the other options). A checkbox for "Only show exact matches" is ticked. A "distribution" dropdown has "raring" selected, and a "section" dropdown is set to "any".

If there are no results, the package you are looking for doesn't exist and the next steps will not work. It may require a third party PPA or an alternative installation method.

If results are found, the package exists and you may continue with these steps:

  1. Open Software Sources (or Software & Updates in 13.04+) by searching for it in the Dash.
  2. Open the "Ubuntu Software" tab.
  3. Ensure that the first 4 checkboxes on this tab are enabled:

Software & Updates panel, on the "Ubuntu Software" tab. There are five options in "Downloadable from the internet", all selected: Canonical-supported free and open-source software (main); Community-maintained free and open-source software (universe); Proprietary drivers for devices (restricted); Software restricted by copyright or legal issues (multiverse); Source code. A "Download from" dropdown is set to "Main server".

  1. Update the package lists, then test with these commands:

     sudo apt update
     sudo apt install <TEST_PACKAGE>
    
8
  • 97
    I found that a simple sudo apt-get update was enough to fix it for me. Your mileage may vary. Mar 7, 2016 at 23:33
  • 5
    sudo apt-get update also worked for me on Ubuntu on Windows 10 (this is important because the UI referenced in the latter half of this answer doesn't exist on that system).
    – James
    Jan 30, 2019 at 18:49
  • Don't forget to search launchpad.net as well!
    – Jonathan
    Apr 13, 2019 at 23:12
  • In my case i only needed to enable the text boxes and it worked after an update ...
    – RegularGuy
    Apr 24, 2019 at 16:04
  • 2
    I'm running my server from the shell, and can't open GUIs. Is it possible to solve this with command line only? May 20, 2019 at 11:42
124

There are many questions about this topic. Here I provide a basic/general answer.

When apt-get install is unable to locate a package, the package you want to install couldn't be found within repositories that you have added (those in in /etc/apt/sources.list and under /etc/apt/sources.list.d/).

The following (general) procedure helps to solve this:

  1. Make sure you have enabled Ubuntu repositories:

    To enable all repositories (main, universe, restricted, multiverse), use the following commands:

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

    Visit Help for more information.

  2. For finding PPA for more packages:

    • Go to Ubuntu Package Search. (Already explained in this answer)
    • If the package that you are unable to locate is from a PPA go to the PPA and check if it is available there for your release.
    • For External Repositories, Visit Ubuntu Updates and search by screen button. or Visit PPAs.
    • Or Search in Launchpad ppa
    • Find appropriate ppa according to your Ubuntu release version.
  3. Add PPA (by command-line):

    Use this command:

    sudo add-apt-repository ppa:<repository-name>
    

    Visit Ubuntu community help for more information.

  4. Don't forget to update (make apt aware of your changes):

    It is essential to run this command after changing any repositories:

    sudo apt-get update
    

    Selecting best download server may help to speed up update.

  5. Finally install the package:

    sudo apt-get install <package>
    

    Refer to Package management by commandline.

Additional/Tip: you can find the correct package-name (i.e the name in the repository) using apt-cache search <package-name>.


  • Related frequently asked Q&A:
  1. How do I resolve unmet dependencies after adding a PPA?
  2. What does "Package <package> has no installation candidate" mean?

Note: If package is not available on repository any how, than you have to wait until it is available (in the case of new/updated versions) or use other installation processes than apt-get e.g. compiling from source, downloading executable binary, etc.

4
  • 3
    It could also be that the user is searching for libname, when it's libname2 in Debian/Ubuntu. Jun 10, 2014 at 14:46
  • 3
    First, is depends on the package and you are making a number of assumptions. First, you are assuming the OP has identified the correct package name, as pointed out by saiarcot895 . Second you are assuming the packages is available. In general, it is best to first identify the problem. Then if at all possible install from the repositories. Unless there is a specific need, ppa is a second choice. If the package is not in the repositories or ppa it may need to be compiled from source. You really do not have enough information.
    – Panther
    Jun 10, 2014 at 15:06
  • @saiarcot895 @bodhi.zazen : Revised answer with providing apt-cache search to find correct package-name from repositories.
    – Pandya
    Sep 11, 2014 at 13:56
  • I accidentally deleted the whole thing: meaning I removed all repositories, which I can imagine other people might have done as well, especially if you're cleaning up your repo list slightly too enthusiastically
    – Gerard
    Dec 3, 2020 at 12:20
16

Fresh Ubuntu installation?

Many times just updating the package lists from all repositories and PPA's does the trick:

sudo apt-get update

This should be the first thing to do.

If this does not work you need search for the repository or PPA which contains the package you are after, add it, and run sudo apt-get update again. Steps for the process are well explained on the other answers on this page.

9

xbmc is only available in the universe repository, only since Ubuntu 12.04 (precise). If you have an older release of Ubuntu, you'll need to upgrade or to get xbmc from another place.

If you have Ubuntu 12.04, make sure that you have turned on the universe repository. You can see what repositories you have enabled in the file /etc/apt/sources.list (and in files in the directory /etc/apt/sources.list.d). Check that this file contains a line like

deb http://al.archive.ubuntu.com/ubuntu/ precise universe

or

deb http://zw.archive.ubuntu.com/ubuntu/ precise main restricted universe multiverse

If you only find a line like

deb http://mn.archive.ubuntu.com/ubuntu/ precise main restricted

and no line with universe, add universe at the end of that line, or a separate line with precise universe, as illustrated above.

If you need to modify /etc/apt/sources.list, run sudo apt-get update afterwards, then try installing again. If the package is still not found, post the complete content of /etc/apt/sources.list and the output of sudo apt-get update.

1
  • @EliahKagan I hadn't thought my answer could be interpreted that way, I tried to clarify. Why not al and zw? (I try to select an appropriate mirror for the OP when they give a clue, but here I have no idea.) Jul 2, 2012 at 20:26
6

I'm new to Ubuntu but i'm writing this as I discovered some solutions to avoid this "Unable to Locate Package" errors. There are three circumstances where this might occur to a shock.

  1. After installing Ubuntu if you don't update it followed by Upgrades, This might occur.
  2. If there are plenty of software updates to occur in future, make sure all important security updates/recommended updates are turned off by typing "Update Manager" on pressing Alt+F2.
  3. Issue One and Two can happen even after updating or clearing all updates. But the eternal solution is: Try point 1 & 2, then type sudo apt-get killmanager, if not working no problem proceed to type sudo apt-get update, then type sudo apt-get upgrade.

Now you should be able to install any software through Terminal.

1
  • If You still get error on "sudo apt-get update" line, try using "sudo apt-get upgrade". This will work.. Guys !! As Linux is highly case sensitive Please make sure you use all commands in smaller letters like "sudo" instead of "Sudo" Dec 25, 2012 at 13:36
6

In the case where tried to install a file:

sudo apt-get install libstdc++.so.6

instead of a package. You get the error message:

E: Unable to locate package libstdc++.so.6
E: Couldn't find any package by regex 'libstdc++.so.6'

because you tried to install a file libstdc++.so.6 that you can't install, because it is located in a debian package.

You can use apt-file to search for the package that contains that file. To install it, type:

sudo apt-get install apt-file

Then you have to update the index.

sudo apt-file update

After that, you can search for the package which contains the file libstdc++.so.6:

sudo apt-file find libstdc++.so.6

Then you find a lot packages that contains the searched file. For this example I paste only one search result:

libstdc++6: /usr/lib/x86_64-linux-gnu/libstdc++.so.6

Then you can install the needed package libstdc++6:

sudo apt-get install libstdc++6
3

you must supply either full path or relative path to reach the xxx.deb file

# bad way since PATH env var does not 
# and should not contain the '.' (current) directory
sudo apt-get install google-chrome-stable_current_amd64.deb 

sudo apt-get install ./google-chrome-stable_current_amd64.deb # proper way

notice in above I supply the relative path to reach the xxx.deb file as in ./xxx.deb this is an intentional security measure to prevent sudo from installing a rogue xxx.deb from a potentially polluted PATH variable

below also works ... its using full path to reach the file

sudo apt-get install /tmp/google-chrome-stable_current_amd64.deb

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .