How to fix Tab completion or bash-completion in Ubuntu & Debian

Some Linux users say they use tab completion or bash-completion features to autocomplete commands. Whatever they may say, it does one of the important tasks is to fetch consequent options, which you are not sure what to put next, or you are too lazy to type the whole command by yourself.

In most Linux distributions, you will find a tab-completion feature, but you won’t find the same in the minimal installation, and without a tab-completion feature, typing long commands or unknown options can be a daunting task for beginners.

So let’s see how you can install and fix the bash-completion feature on the minimal version of Ubuntu or any other Debian-based distribution.

Install Tab completion on Ubuntu & Debian based distro

As we already discussed, the bash-completion utility is not available in the minimal version, so you need to install and download bash completion on your machine, but what about those who have installed the full-fledged version of Ubuntu or Debian?

Those users can run the below command to check whether the bash-completion utility is installed or not. If the output displays “bash-completion”, then you can skip this section and read “How to re-install bash-completion on Ubuntu”.

$ dpkg --list | grep bash-completion

To install bash-completion on your minimal version, pass the single line of command to start the installation:

$ sudo apt install bash-completion 

Once the installation is complete, restart your system, or else you can restart your current shell and then try to test the bash feature by invoking any of the commands.

I tried to get all the available options for the rm command by pressing the tab button.

$ rm -[PRESS-TAB]
Check bash completion feature
Check bash completion feature

Still, if your problem persists, then you should look at your .bashrc file, which is located in your home directory, and find the below line. If it is not available, then add it to .bashrc using the available command-line editor.

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
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

Sometimes you may find the above line commented. If that is the case, then uncomment the line from “if” to the last line of “fi” as in the below image.

Once you add or remove the comment from the .bashrc file, refresh the changes by invoking the source command.

$ source ~/.bashrc 

I believe your problem will be resolved after following the above steps. If the problem still exists, then the last resort is to re-install bash completion on your Ubuntu or Debian-based distributions.

Re-install bash-completion on Ubuntu/Debian

To re-install bash completion on your system is as simple as the installation. You just need to use the --reinstall option with the regular installation command.

Do copy and paste the below code into your terminal screen.

Reinstall bash completion utility
Reinstall bash-completion utility

Once the installation is over, re-login and test out the tab completion functionality.

That’s all to solve Tab completion or bash-completion in Ubuntu and Debian. If the problems still persist, do let me know in the comment section.

If you are facing the same issue in RHEL-based distributions then you can follow: Enable Bash Auto-Completion in AlmaLinux/RHEL

Leave a Reply