Bash history not saved after closing terminal

It may be that your .bash_history doesn't belong to your user. Check the permissions of the file and if you're not the owner, change it:

sudo chown yourusername:yourusername ~/.bash_history

First type following command

shopt -s

to check weather histappend command is 'on' or 'off' If it is off then type following command to append history

history -a

If you want to save history with every new prompt run following command

export PROMPT_COMMAND='history -a'

For more information see this link