apt-get autocomplete package name is broken

108,487

Solution 1

As stated in the comments to the other answer, first make sure that bash-completion is installed:

sudo apt-get install bash-completion

and apparently for @diapir, it helped to reinstall it:

sudo apt-get install --reinstall bash-completion

However, for me, the problem was not that bash-completion was not installed or broken, the problem was that I had accidently deleted my .bashrc file. You can get a new one by copying it from /etc/skel:

cp /etc/skel/.bashrc ~/

Solution 2

Type the following command:

sudo -H gedit /etc/bash.bashrc

Look for these lines:

# enable bash completion in interactive shells
# if ! shopt -oq posix; then
#  if [ -f /usr/share/bash-completion/bash_completion ]; then
#    . /usr/share/bash-completion/bash_completion
#  elif [ -f /etc/bash_completion ]; then
#    . /etc/bash_completion
#  fi
# fi

Uncomment some lines, to make it look like this:

# enable bash completion in interactive shells
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

Save, close terminal, then reopen it.

I have this issue after installing 13.04, and that's how I resolve it.

Solution 3

Note that output of this command:

apt-config dump | grep "Dir::Cache"

Should be something like this:

Dir::Cache "var/cache/apt";
Dir::Cache::archives "archives/";
Dir::Cache::srcpkgcache "srcpkgcache.bin";
Dir::Cache::pkgcache "pkgcache.bin";

If value of Dir::Cache::pkgcache is empty, apt will not be able to auto complete package names. Take a look at your /etc/apt/apt.conf.d/ files and search for this key to be sure that it's not set to empty string.

grep -r pkgcache /etc/apt/apt.conf.d/

Also take a look at this answer.

Solution 4

Download the latest stable release from http://bash-completion.alioth.debian.org/

./configure
make
sudo make install

insert

if [ -f /etc/bash_completion ]; then
  . /etc/bash_completion
fi

to ~/.bashrc

Share:
108,487

Related videos on Youtube

Cosmin Stefaniga
Author by

Cosmin Stefaniga

I'm love Ruby on Rails

Updated on September 18, 2022

Comments

  • Cosmin Stefaniga
    Cosmin Stefaniga almost 2 years

    At some moment

    apt-get install
    

    autocomplete was broken

    It was very useful to me to see packages name with Tab press

    How to repair this autocomplete?

    • Oli
      Oli over 12 years
      Please edit your question to add more information. What does it do now when you press tab? Is there an error? Please include it.
    • koolhead17
      koolhead17 over 12 years
      What package you were trying to find? Is it available via apt-cache search mypkg I am using Kubuntu on Oneiric i see it working well.
    • Cosmin Stefaniga
      Cosmin Stefaniga over 12 years
      For example I press tab after sudo apt-get install ruby, and terminal display me all packages with ruby: ruby-mysql, ryby-dev, etc.
    • Oli
      Oli over 12 years
      Yes, and what do you see instead when you press tab?
    • Cosmin Stefaniga
      Cosmin Stefaniga over 12 years
      I see folders list, like cd +[TAB]
  • Caesium
    Caesium over 12 years
    bash-completion is in packages - is there any reason you did it manually? The package should do pretty much exactly this :)
  • Cosmin Stefaniga
    Cosmin Stefaniga over 12 years
    :) as always, sitting, reading manuals, configure, and then it turns out that this soft is exists in the repository
  • coda
    coda about 12 years
    sudo apt-get install --reinstall bash-completion did it for me.
  • Anwar
    Anwar about 12 years
    @diapir, I have the same problem, but only reinstall does not working. I have to apply the lines in bashrc file.
  • BHSPitMonkey
    BHSPitMonkey over 11 years
    Thanks, the bashrc tip solved the problem for me as well. The use of sudo on the chmod command is unnecessary though, right?
  • Kevin
    Kevin about 10 years
    the file located in /etc/ is 0644/-rw-r--r-- with user:group = root:root, and when copied to your user folder, will automatically go to user:user
  • Jacob Abraham
    Jacob Abraham over 8 years
    cp /etc/skel/.bashrc ~/ helped me solve this problem.
  • this.foo
    this.foo over 8 years
    this was the only thing that worked for me. thank you.
  • Sergey
    Sergey about 8 years
    Reinstall and copied /etc/skel/.bashrc helped me, thank you!
  • Rodrigo Lopez Guerra
    Rodrigo Lopez Guerra about 7 years
    Worked for me on Elementary OS LoKi
  • Alan Wang
    Alan Wang over 4 years
    Looks like this (and the link) is the correct answer if you have this issue inside a docker container.
  • Dave Ankin
    Dave Ankin over 3 years
    this still works tysm! just do rm /etc/apt/apt.conf.d/docker-clean
  • polynomial_donut
    polynomial_donut almost 3 years
    I just needed to reinstall bash-completion after upgrading from Debian 9 to Debian 10