Whenever I open a new instance of a terminal, the history is empty. Why is that? Do I need to set something up? In bash there's no need for this, though.
Bash and zsh have different defaults. Zsh doesn't save the history to a file by default.
When you run zsh without a configuration file, it displays a configuration interface. In this configuration interface, select
(1) Configure settings for history, i.e. command lines remembered and saved by the shell. (Recommended.)
then review the proposed settings and select
# (0) Remember edits and return to main menu (does not save file yet)
Repeat for the other submenus for (2) completion, (3) keybindings and (4) options, then select
(0) Exit, saving the new settings. They will take effect immediately.
from the main menu.
The recommended history-related settings are
HISTFILE=~/.histfile HISTSIZE=1000 SAVEHIST=1000 setopt appendhistory
I would use a different name for the history file, to indicate it's zsh's history file. And 1000 lines can be increased on a modern system.
HISTFILE=~/.zsh_history HISTSIZE=10000 SAVEHIST=10000 setopt appendhistory
These lines go into
~/.zshrc, by the way.
While the existing answer is correct, I thought it might be worth adding that there's possibly a better option than
appendhistory for saving your history and this is
From the docs
SHARE_HISTORY "both imports new commands from the history file, and also causes your typed commands to be appended to the history file". This means that shells are aware of each other's history as well without having to close the current one or open a new one.
So, all together you'd set it like this:
HISTFILE=~/.zsh_history HISTSIZE=10000 SAVEHIST=1000 setopt SHARE_HISTORY
when you first switch over from bash to zsh, your bash history will not carry over. So all the history you had in bash is still in bash's history file. zsh starts capturing history from the time you start using it as your shell.
If you did not set it up to capture history, you can re-run the config wizard and tell zsh how much history to save. Either change the name of ~/.zshrc or delete it to get a new shot at the wizard.