首页 / 后端 / GO / MacOs配置go环境变量
MacOs配置go环境变量
歪脖37684 GO
798浏览
2022-01-21 03:11:50

1:查看当前环境变量

env

2:环境变量配置

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

cd ~
ls -all

2>如果不存在.bash_profile文件,在终端输入下面命令创建

touch .bash_profile

3>编辑.bash_profile文件

open -e .bash_profile

此时可以在.bash_profile直接输入需要的环境变量

4>保存文件,关闭.bash_profile;

5>更新刚配置的环境变量

source .bash_profile

6>环境变量配置成功,再次输入env命令校验

3:常见问题

重启终端后配置的环境变量失效,或提示MacOS .zshrc does not exist问题

原因:

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

解决:

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

cd ~
ls -all

2>如果.zshrc不存在,在终端输入下面命令创建

touch .zshrc

3>编辑.zshrc文件

open -e ~/.zshrc

4>在最后一行输入下面代码后保存

source ~/.bash_profile

5>在终端执行下面命令,立即生效

source ~/.zshrc
相关推荐