go get无法使用错误排查

今天在使用go get 安装gin的时候无法下载,错误如下(我用的mac m1本):

前提:先检查GO111MODULE="on" 是否开启

go % go get -u github.com/gin-gonic/gin

go: go.mod file not found in current directory or any parent directory.
'go get' is no longer supported outside a module.
To build and install a command, use 'go install' with a version,
like 'go install example.com/cmd@latest'
For more information, see https://golang.org/doc/go-get-install-deprecation
or run 'go help get' or 'go help install'.

这个翻译了下,说是没在go.mod里面执行,于是用go env 查看环境,找到go.mod 的位置

 

 这个提醒因该是我当前安装目录下没有这个文件,于是执行了go mod init xxx文件名,在文件下生成go.mod文件

这时候再执行go env

 

 然后再执行安装命令,又提示:

go get -u github.com/gin-gonic/gin

go: could not create module cache: mkdir /usr/local/bin/go: permission denied

这个就很好理解了,没有权限,于是执行下面的命令解决

注意:新版本的mac系统,权限很多都没有,是需要手动给权限的

sudo go get -u github.com/gin-gonic/gin

posted @ 2022-05-30 14:47  绝世老中医  阅读(4688)  评论(0编辑  收藏  举报