Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the module cache in golang?

Tags:

go

vgo

When I enable gomodules and build my go program then the required packages are downloaded.

But I cannot find them in $GOPATH/src/ or in $GOPATH/src/mod.

Where are they stored?

export GO111MODULE=on
go mod init
go build main.go 
go: finding github.com/sirupsen/logrus v1.0.6
go: downloading github.com/sirupsen/logrus v1.0.6
...
like image 478
christian Avatar asked Sep 01 '18 09:09

christian


People also ask

Where does go save modules?

What is Go Module. A Module is a collection of Go packages stored in a file tree under $GOPATH/pkg folder with a go. mod file at its root.

What is go mod cache?

go clean -modcache This command is used to clear the mod cache which is stored at $GOPATH/pkg/mod . This command is used to remove the installed packages. The -modcache flag removes the entire module download cache, including unpacked source code of versioned dependencies.

Where do mod downloads go?

Modules may be downloaded directly from version control repositories or from module proxy servers. A module is identified by a module path, which is declared in a go. mod file, together with information about the module's dependencies. The module root directory is the directory that contains the go.


3 Answers

For Go 1.11, they are stored in

$GOPATH/pkg/mod
like image 161
peterSO Avatar answered Oct 12 '22 17:10

peterSO


I'm on Macos 10.13.6, using go1.11 darwin/amd64 and echo $GOPATH is empty.

I found my modules in $HOME/go/pkg/mod

like image 37
Luke Bayes Avatar answered Oct 12 '22 17:10

Luke Bayes


Run this in terminal

go env GOMODCACHE

go env - Print all Go environment information

go env NAME - Print specific env var.

like image 44
Sany Liew Avatar answered Oct 12 '22 17:10

Sany Liew