解决报错Error: could not create module cache: mkdir /usr/local/sbin/pkg: permission denied

实验环境

操作系统:Ubuntu 20.04
IDE: Goland
go安装位置(默认):/usr/local

报错

Error: could not create module cache: mkdir /usr/local/sbin/pkg: permission denied

解决方法

进入管理员模式
1.使用vi /etc/profilevi ~/.bashrc检查环境变量是否配置如下

 export GOROOT=/usr/local/go
 export GOPATH=$HOME/go
 export PATH=$PATH:/usr/local/go/bin

2.使用cd /usr/local进入go安装所在文件夹
3.在该路径下运行命令chmod -R 777 .
4.重启Goland,问题解决

参考文献

1.golang mkdir /usr/local/go/pkg/mod permission denied