Why bash history on my mac won't save?

I have always used bash for work, and never had problems with it. Now, it does not save any command in history again. If I open a window terminal, try some commands, it acts like everything has worked fine and show me history using the arrow keys. But If I close the window (and that it is the time that it supposed to be save on the .bash_history file) and open another one, there are no signs of the last commands.

How can I find out what is going wrong? Or re-set everything from blank.


I did this:

Add a variable to .bash_profile file

SHELL_SESSION_HISTORY=0

restart the terminal and after that it is working as I'd like. (It saved the commands after I closed the terminal)

P.S. I also use the HISTFILESIZE and HISTSIZE variables

HISTSIZE is the number of lines or commands that are stored in memory in a history list while your bash session is ongoing.

HISTFILESIZE is the number of lines or commands that (a) are allowed in the history file at startup time of a session, and (b) are stored in the history file at the end of your bash session for use in future sessions.


Starting in OS X 10.11 El Capitan, the system-installed script /etc/bashrc_Apple_Terminal coordinates with Terminal in order to save/restore separate command histories for each terminal restored for Resume.

Read the comments in /etc/bashrc_Apple_Terminal for an explanation of how it manages per-terminal command histories and how to customize it.

If you customize PROMPT_COMMAND be sure to concatenate to the previous value so you don't wipe out the system-supplied command:

PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND; }your_code_here"

If you install an EXIT signal handler with trap be sure to do something similar (or call shell_session_update from your handler if you can't figure out how to concatenate to the previous value—it's a little involved).

When you exit the shell, this code will save new commands to the terminal's history in ~/.bash_sessions. To see if it encounters any problems, instead of closing the terminal exit the shell manually with exit (or Control-D). It logs progress messages. Note if it doesn't complete or if any sort of warning or error messages are displayed.

In general, bashrc_Apple_Terminal attempts to detect and disable per-session history if it looks like the user has performed any customizations that aren't compatible with it. It sounds like you may have found one it doesn't handle. Please consider filing a bug report with Apple: https://developer.apple.com/bug-reporting/


On a fresh install of Mac OS X (updated to 10.13.6), bash command history was not being saved. There were also no .bashrc or .bash_profile files. In this case, just adding an empty .bashrc file fixed it for me.

touch .bashrc

That's seems to be all you need...


Just in case there are others out there that have RVM (Ruby Version Manager) installed: Check to see if you have the following line in your ~/.profile, ~/.bashrc or ~/.bash_profile files.

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

It's probably RVM preventing the exit "hook" for bash_sessions to run.

That was the problem for me. Try commenting it out.

Source: Reddit