How to Fix Tab Completion Not Working in Ubuntu & Debian

On Linux Handbook, I always test things before writing. Other contributors do the same.

Since we are going to cover a lot of DevOps, SysAdmin and scripting related tutorials in the future, I created a dedicated test server on UpCloud. UpCloud is a cloud server provider with excellent performance.

One of the first few things I did was to create a sudo user on this newly created test server running Ubuntu 18.04 LTS. While using the server, I noticed something weird.

The tab completion was not working properly. Tab completion is one of the essential terminal shortcuts I cannot live without. Imagine the horror of working in Linux command line where tab completion is not working. It negatively impacts your productivity and you feel like an important part of your terminal is missing.

Good thing is that it can be easily fixed. Let me show you how.

Enable tab completion in Ubuntu and Debian based Linux distributions

Tab completion is so much a part of Linux that you would never think that this is something that needs to enabled explicitly. Unfortunately, that’s how it works.

You see, some cloud servers prefer to have a minimal image of the Linux distribution because it saves time in deployment. But this also means that the Linux install will have only a handful of packages.

And that’s what happened in this case. The newly installed Ubuntu server was missing the bash-completion package.

You can quickly and easily install this package using the standard apt command:

sudo apt install bash-completion

You’ll need to logout (or exit the shell) to see its effect.

Further troubleshooting the auto completion

Normally, this should fix the problem but if bash-completion is already installed and you still have the problem, you may try reinstalling it.

sudo apt install --reinstall bash-completion

Log out and check if it works or not. If not, you can manually edit your bash configuration file present at ~/.bashrc

If it doesn’t exist already, you should create it. You can then add the following lines to your bashrc file:

# 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

You can edit the file in terminal using a terminal based text editor like Vim.

I hope this quick little tutorial fixed the tab completion problem for you. If you have any questions or suggestions, please feel free to leave a comment.