环境变量配置
- cd ~ (回到主目录home)
- 如果你是第一次配置环境变量,可以使用“touch .bash_profile” 创建一个.bash_profile的隐藏配置文件
- vim .bash_profile,写入相应的环境变量,如下:
# golang配置
export GOROOT=/usr/local/Cellar/go/1.10.2/libexec
export GOBIN=$GOPATH/bin
export GOPATH=$HOME/go
export PATH=$PATH:$GOBIN:$GOROOT/bin
- source ./bash_profile 使环境变量生效
解决每次都需要使用source ./bash_profile 重新生效环境变量
问题
在 ~/.bash_profile 中配置环境变量, 可是每次重启终端后配置的不生效.需要重新执行 : $source ~/.bash_profile后,才会生效。
原因
在bash中配置的环境变量,而当前系统是使用的是shell
查看当前使用的shell:
- 终端输入:echo $SHELL
- 输出是/bin/zsh,说明使用的是zsh
解决办法
在.zshrc文件加中添加source ~/.bash_profile,方法如下
- 进入主目录 cd ~
- 显示隐藏文件,找到.zshrc文件夹