75

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?

5
  • Please edit your question to add more information. What does it do now when you press tab? Is there an error? Please include it.
    – Oli
    Dec 9, 2011 at 10:21
  • 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.
    – koolhead17
    Dec 9, 2011 at 11:18
  • For example I press tab after sudo apt-get install ruby, and terminal display me all packages with ruby: ruby-mysql, ryby-dev, etc. Dec 9, 2011 at 11:51
  • Yes, and what do you see instead when you press tab?
    – Oli
    Dec 9, 2011 at 11:56
  • I see folders list, like cd +[TAB] Dec 9, 2011 at 11:59

4 Answers 4

114

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 ~/
5
  • 2
    Thanks, the bashrc tip solved the problem for me as well. The use of sudo on the chmod command is unnecessary though, right? Dec 24, 2012 at 4:32
  • 2
    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
    – Kevin
    May 28, 2014 at 17:07
  • cp /etc/skel/.bashrc ~/ helped me solve this problem. Nov 15, 2015 at 8:54
  • Reinstall and copied /etc/skel/.bashrc helped me, thank you!
    – Sergey
    Apr 27, 2016 at 10:19
  • I just needed to reinstall bash-completion after upgrading from Debian 9 to Debian 10 Aug 10, 2021 at 21:13
38

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.

2
  • this was the only thing that worked for me. thank you.
    – this.foo
    Nov 27, 2015 at 7:40
  • Worked for me on Elementary OS LoKi Apr 5, 2017 at 14:43
7

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.

2
  • 3
    Looks like this (and the link) is the correct answer if you have this issue inside a docker container.
    – Alan Wang
    Feb 24, 2020 at 14:00
  • this still works tysm! just do rm /etc/apt/apt.conf.d/docker-clean
    – Dave Ankin
    Feb 14, 2021 at 15:45
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

4
  • bash-completion is in packages - is there any reason you did it manually? The package should do pretty much exactly this :)
    – Caesium
    Dec 10, 2011 at 12:46
  • :) as always, sitting, reading manuals, configure, and then it turns out that this soft is exists in the repository Dec 10, 2011 at 12:57
  • 4
    sudo apt-get install --reinstall bash-completion did it for me.
    – diapir
    Apr 30, 2012 at 0:48
  • 2
    @diapir, I have the same problem, but only reinstall does not working. I have to apply the lines in bashrc file.
    – Anwar
    May 13, 2012 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.