MacOS配置.bash_profile,重启终端后配置失效和MacOS .zshrc does not exist问题

MacOS配置.bash_profile,重启终端后配置失效和MacOS .zshrc does not exist问题

场景

? 在Mac中配置golang环境变量更改GOPATH路径,在~/.bash_profile中配置新的路径,source ~/.bash_profile之后关掉终端,再用go env查看GOPATH发现路径又还原了。

原因

? 使用的终端是zsh,zsh加载的是~/.zshrc文件,而该文件中没有定义任务环境变量。

解决

1、打开终端在用户目录下(cd ~)执行ls -all 查看该目录下是否存在.zshrc文件,

? 如果不存在,则需要创建该文件,和.bash_profile的创建方法一致,在用户路径下 touch .zshrc

2、在终端中执行命令打开.zshrc文件

open -e ~/.zshrc

3、在文件最后一行加上下面代码并保存退出

source ~/.bash_profile

4、执行命令,使其立即生效

source ~/.zshrc

MacOS配置.bash_profile,重启终端后配置失效和MacOS .zshrc does not exist问题

上一篇:linux make swap


下一篇:Linux常用命令(一)