Add Alias and Export to Terminal on Mac

On macOS, Zsh is available as the default shell starting from macOS Catalina (10.15) and later versions. Note that Zsh is backward compatible with Bash, so you can still use Bash commands and scripts within Zsh. In this entry, I will cover common tips on using and configuring Zsh.

On macOS, the .zshrc file is a configuration file for the Zsh shell.

Set Export and Alias in Zsh

To setup .zshrc, open .zshrc

echo 'export JAVA_HOME=`/usr/libexec/java_home -v 1.17`' >> ~/.zshrc 
echo 'alias mkubectl="minikube kubectl --"' >> ~/.zshrc 
echo 'source /path-to/.zshrc' >> ~/.profile

such as

echo 'export JAVA_HOME=`/usr/libexec/java_home -v 1.17`' >> ~/.zshrc 
echo 'alias mkubectl="minikube kubectl --"' >> ~/.zshrc 
echo 'source /Users/jchiang/.zshrc' >> ~/.profile

Then you can open a new terminal and verify the exported variables as well as alias

echo $JAVA_HOME
mkubectl