MAC下~/.bash_profile无效

~/.bash_profile生效的前提是我们需要使用bash作为终端,随着系统的升级MAC会将默认终端切换为zsh,如果我们稍不注意按照提示进行了修改,那么就会导致~/.bash_profile无效(本人就是这种情况)。

The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.

这个问题有两种解决方法:
第一种,将终端切换为bash

chsh -s /bin/bash

重新打开终端即可。

第二种:继续使用zshzsh不会自动加载~/.bash_profile,而是自动加载~/.zprofile文件,所以只需要在该文件中引用~/.zprofile即可。

# 进入根目录
cd ~  
# 创建zprofile文件
touch .zprofile
# 编辑
vim .zprofile
# 使文件生效
source .zprofile

~/.zprofile文件内容如下:

if [ -f ~/.bash_profile ]; then
    source ~/.bash_profile
fi

以上两种方式根据个人喜好自由选择


版权声明:本文为jianggujin原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。