I am on Debian Jessie 8.6. I noticed that apt-get gets the expected bash autocompletion when pressing tab for packages and command, but when trying to use it with apt it does not work. I remember using xubuntu 16.04 where it worked, so I find it strange that it does not work here. Is there a way to enable it for the command apt as well? If so, how?

  • Did anything work for you?
    – Lynob
    Jul 25, 2019 at 20:38
  • @Lynob I ended up moving to Ubuntu, so I can't help you, sorry.
    – Andrea
    Jul 27, 2019 at 13:02

7 Answers 7


Debian does not come with 'bash-completion' installed and enabled.

If you're coming to Debian from, say, an Ubuntu background, where it is pre-installed and enabled by default, this can be a source of some confusion.

To enable/'fix' this, run (as root):

apt-get install bash-completion

Then, you have two options. You can either:

 1. Enable it on a per-user basis for yourself, or

 2. Enable it globally.

1. If you want to enable it for just your user, edit ~/.bashrc - add the following:

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

To try it without logging out and back in, run:

    . ~/.bashrc

Or open a new shell. Then try to use tab-completion with apt. That dot and space at the beginning (. ) is the same as using the source keyword in bash, but is more portable.

If you want it to work when su'd into the root account, do the same thing in root's home directory (typically /root).

2. To enable it globally, do the changes from (1) in the file /etc/bash.bashrc instead.

To anyone who's wondering why this works, the . in front of /etc/bash_completion does not refer to the current directory, since it has spaces around it. It instead makes the contents of the given file be evaluated in the currently running shell, instead of being executed in a new subshell. It is standardized here.

In Bash, this . can be replaced by the command source, but this is not standardized by POSIX and is less portable so I tend to steer people away from using it. In this case, since it is specifically a program for extending bash, rather than something that needs to work in a bourne shell or ksh, you can feel free to substitute source for readability.

Incidentally, this behavior (not opening a sub-shell) is similar to the way DOS/Windows .BAT scripts work normally, changing the state of the shell they are run in. This is why if you cd into a different path in a shell script, you won't be in that path when the script exits like you would be in a .BAT.

  • 3
    I already did these steps, but that didn't help. Only works with apt-get, but apt doesn't.
    – Andrea
    Sep 26, 2016 at 15:36
  • @Andrea Oh, sorry, I didn't fully read your question, I guess. I'm not at my Debian box at the moment (in windows, all I've got is cygwin, unfortunately), but I'll try to figure it out from my debian machine when I'm back home.
    – Wyatt Ward
    Sep 26, 2016 at 19:20

In Debian 9 Stretch just edit /etc/bash.bashrc and uncomment:

# 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
  • I have that uncommented as well, apt still gets no auto completion Aug 10, 2021 at 21:07

How I solved it

I had auto completion problems trying to autocomplete wget with apt-get install wg[TAB][TAB] and I managed to solve it by removing the --no-generate parameter from the flies below:


It is worth mentioning that these files are available only after you install bash-completion.

The --no-generate parameter I'm referring to can be seen in the line below, but I removed ALL --no-generate, not only from this line: https://github.com/scop/bash-completion/blob/master/completions/apt-get#L28

How did I come to this point?

I got to this point after running set -v previous to apt-get install wg[TAB][TAB], which showed that the command executed was:

apt-cache --no-generate pkgnames wg

and the output was an error:

E: Could not open file  - open (2: No such file or directory)

When I executed apt-cache pkgnames wg without the --no-generate I correctly got the list for autocompletion:

root@484f5c8f56ba:/# apt-cache pkgnames wg

Hope this helps.

  • That was exactly what I needed. Thanks :D
    – Ceisc
    Jan 10, 2020 at 22:35

The problem is most probably caused by

Dir::Cache::pkgcache "";
Dir::Cache::srcpkgcache "";

settings in /etc/apt/apt.conf.d (typically in a file named docker-clean). In my case, it originated from Debian Docker image, see https://github.com/debuerreotype/debuerreotype/blob/799473bee3d388cf00bd55221b38a9d58bd6a2ba/scripts/debuerreotype-minimizing-config


Copy this configuration file from Ubuntu: /usr/share/bash-completion/completions/apt to the same directory in Jessie. You can also get the file here: http://pastebin.com/PRBMt3an

  • This is what I need. But auto completion is not working for apt, after I copied, renamed the downloaded apt file to the /usr/share/bash-completion/completions/. How to make it work?
    – klor
    Jan 27, 2019 at 14:38
  • The pastebin.com/PRBMt3an file was in Windows CR LF linefeed, this is why it did not work. I had to convert line format to Unix LF linefeed, so then worked after starting a new terminal.
    – klor
    Mar 17, 2019 at 13:56
  • Here is the 'apt' file with correct linefeed: filedropper.com/apt_1
    – klor
    Mar 17, 2019 at 14:08
  • This will work, but it's basically just implementing what I do in my answer. If you do it this way instead, know that you can use dos2unix to convert the line endings on files from pastebin (you might have to install it, though). You can also use this command, but to get the ^M Carriage Return character you'll need to do ctrl-v ctrl-m; the 'carat-capital-M' won't actually work as is off the clipboard: sed 's/^M$//' < file-to-fix > fixed-file.
    – Wyatt Ward
    Apr 28, 2020 at 2:02
  • Line 161 says autocleean. Don't think that's how it is supposed to be spelled. That begs the question, is this file genuinely from Ubuntu? Jul 17, 2023 at 13:35

Applies to docker containers!

The content of your /etc/apt/apt.conf.d/docker-clean file shows that it is configured to clean up package archives and caches after package installation and updates. However, the specific lines Dir::Cache::pkgcache ""; Dir::Cache::srcpkgcache ""; seem to be causing the issue with auto-completion. To address this issue, you can modify the Dir::Cache::pkgcache and Dir::Cache::srcpkgcache directives to point to the correct cache directories. Here's an example:

DPkg::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };
APT::Update::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };
Dir::Cache::pkgcache "/var/cache/apt/pkgcache.bin"; Dir::Cache::srcpkgcache "/var/cache/apt/srcpkgcache.bin";

This modification sets the Dir::Cache::pkgcache and Dir::Cache::srcpkgcache to point to the standard cache directories used by APT. After making this change, save the file and then run the following command to update the APT cache:

sudo apt update

The alternative is to use a extension on top of apt. At least it is nicer and autocompletion works. On the double Tab. Nala. Nala apt frontend

You must log in to answer this question.

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