"go get" fails as : "go: cannot determine module path for source directory /Users/sshridhar (outside GOPATH, no import comments)"

Hi All,

I am on Mac OS.

SETUP:

This is my current setup for PATHs:

$ echo $PATH
/Users/sshridhar/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/anaconda3/bin:/usr/local/apache-maven-3.5.4/bin:/Users/sshridhar/go/bin:/usr/local/opt/go/libexec/bin

$ echo $GOPATH
/Users/sshridhar/go
$ echo $GOBIN 
/Users/sshridhar/go/bin
$ echo $GOROOT   
/usr/local/opt/go/libexec

Go install location:

$ pwd 
/Users/sshridhar/go
$ ls  
bin pkg src

Go ENV:

go env
GOARCH="amd64"
GOBIN="/Users/sshridhar/go/bin"
GOCACHE="/Users/sshridhar/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/sshridhar/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/opt/go/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/sshridhar/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/t9/mfm7png979g0zllnllnqspyr0000gn/T/go-build146906349=/tmp/go-build -gno-record-gcc-switches -fno-common"

ISSUE:

My go get fails as follows:

$ go get https://github.com/golang/example
go: cannot determine module path for source directory /Users/sshridhar (outside GOPATH, no import comments)

$ go get http://github.com/golang/example
go: cannot determine module path for source directory /Users/sshridhar (outside GOPATH, no import comments)

$ go get http://github.com/golang/example.git
go: cannot determine module path for source directory /Users/sshridhar (outside GOPATH, no import comments)

It always tried to go to /Users/sshridhar where as go folders are here : /Users/sshridhar/go

I have had similar setup working earlier. Not sure, what has changed meanwhile. Any help on resolving this.

I think this is the problem. Does this file exist? Your go thinks it is inside a program with modules so then you run go get it tries to update this file but it is maybe empty or contains not the module path.

1 Like

Thanks.

Yep. There is no file at : /Users/sshridhar/go.mod

So, I did export GOMOD = “”, added to my .bashrc (sourced), but go env doesnt seem to pick that. Where/how should i change that ? and should i keep it “” ?

This is what i did and has fixed the issue.

My .bashrc looked like following before the fix:

export GOPATH=/Users/sshridhar/go
export GOROOT=/usr/local/opt/go/libexec
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin
export GOBIN=$GOPATH/bin
export PATH=$PATH:/Users/sshridhar/go
export GO111MODULE=on

I changed last line to : export GO111MODULE=auto, sourced bashrc and then my go env was like this:

$ go env
GOARCH="amd64"
GOBIN="/Users/sshridhar/go/bin"
GOCACHE="/Users/sshridhar/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/sshridhar/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/opt/go/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/t9/mfm7png979g0zllnllnqspyr0000gn/T/go-build974052246=/tmp/go-build -gno-record-gcc-switches -fno-common"

No more GOMOD in above go env

Things work now…

Thanks @johandalabacka for the help!

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.