如何修复 $GOPATH/go.mod 存在但不应存在的问题 – Linux Fedora

huangapple go评论84阅读模式
英文:

How do I fix $GOPATH/go.mod exists but should not - Linux Fedora

问题

我是你的中文翻译助手,以下是翻译好的内容:

我对Golang还不熟悉,我正在按照这个教程进行学习:https://golang.org/doc/tutorial/getting-started,但是每次尝试运行代码时都会收到以下错误信息:

$GOPATH/go.mod exists but should not

我尝试查看了像这个回答:https://stackoverflow.com/a/62062562/9785222 这样的解决方案,但是我不明白GOPATH是什么,它在哪里。

我在Linux Fedora上使用Vi作为编辑器。

英文:

I am new to Golang, I am following this tutorial <https://golang.org/doc/tutorial/getting-started> but for some reason I keep getting this message every time I try to run the code:

$GOPATH/go.mod exists but should not

I have tried to look at answers like this one: <https://stackoverflow.com/a/62062562/9785222> but I dont understand what is GOPATH and where is it.

I am using Vi as an editor on Linux Fedora

答案1

得分: 5

GOPATH 在 Unix 上的默认值是 $HOME/go。

删除文件 $HOME/go/go.mod 或者显式地将 $GOPATH 设置为其他目录。

英文:

GOPATH defaults to $HOME/go on Unix.

Remove the file $HOME/go/go.mod or explicitly set $GOPATH to a different directory.

答案2

得分: 2

$GOPATH应该指向src目录,在我的情况下,在Debian中,我将$GOPATH设置为/usr/local/go/src,问题就解决了。

export $GOPATH=/usr/local/go/src

GOPATH是什么?

GOPATH是一个变量,它定义了一个文件夹,在该文件夹下,GO期望我们的代码存在。更多详情,请参考这个链接

英文:

$GOPATH should point out to the src directory, in my case in Debian, I set $GOPATH to /usr/local/go/src and the problem was solved.

export $GOPATH=/usr/local/go/src

What is GOPATH ?

GOPATH is a variable that defines a folder, under which GO expects our code to reside . For more details, you can check this link

huangapple
  • 本文由 发表于 2021年7月3日 10:16:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/68232734.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定