Reputation: 812
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
Upvotes: 16
Views: 38245
Reputation: 121119
GOPATH defaults to $HOME/go
on Unix.
Remove the file $HOME/go/go.mod
or explicitly set $GOPATH
to a different directory.
Upvotes: 9
Reputation: 1
For me it was solved by upgrading the golang image :
FROM golang:1.20 AS gobuild
FROM golang:1.23.1 AS gobuild
Upvotes: -1
Reputation: 400
For me this was when trying to build in a docker container. It was solved by using a different build directory to the default.
E.g.:
FROM golang:1.21 AS gobuild
WORKDIR /build
Upvotes: 3
Reputation: 2062
$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
Upvotes: 3