Bash Tab Auto-complete not working for apt

apt-get install and apt-cache policy do not complete package names.

I have double checked /etc/bash.bashrc, no irregularities.

Googled for answers but none suffice.

Any help/advice?


Solution 1:

Open /etc/bash.bashrc with gedit or other text editor and uncomment the following lines:

#if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
#    . /etc/bash_completion
#fi

It works for me.

On Ubuntu 16.04 the it looks like this:

#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

Solution 2:

Actually, I found the solution ~

Install the auto-complete-el

sudo apt-get install auto-complete-el 

Install via the software center

After installing this package, I got everything back to normal.

Solution 3:

Is your shell prompt looking like $ instead of user@host:~$? If yes, then it could be case of wrong shell causing problem with autocompletion. Try changing login shell to /bin/bash from /bin/sh as below.

sudo chsh -s /bin/bash *username*