英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论