less than 1 minute read

macOS 10.15 将默认的终端由 bash 更换为 zsh,由于 zsh 的配置文件为 ~/.zshrc,因此其不会读取 ~/.bashrc 文件,致使原有 bash 未能生效。

解决方式为新增一个配置文件 ~/.profile,在 ~/.bashrc~/.zshrc 中均通过 source 执行 ~/.profile

以配置 nvm 为例,~/.profile 中内容如下:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

~/.bashrc 中内容如下:

source ~/.profile

~/.zshrc 中内容如下:

[[ -e ~/.profile ]] && emulate sh -c 'source ~/.profile'

至此,不论终端为 bash 或 zsh,打开时都会执行 ~/.profile

参见