ColonelKenny
ColonelKenny

Reputation: 388

Go Get Not Downloading to SRC Folder

Expected: I install the package using go get, and it creates all necessary folders in the src folder, but they only appear in the pkg/mod folder and I can’t use them.

Reality: it says it’s downloading, finishes, then nothing.

Everything is setup correctly in Windows Env Variables, this just.. doesn’t work.

Command Used: go get github.com/fatih/color

Go Env:

set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\admin\AppData\Local\go-build
set GOENV=C:\Users\admin\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\admin\Desktop\gostuff\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\admin\Desktop\gostuff
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.16
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\admin\AppData\Local\Temp\go-build639062626=/tmp/go-build -gno-record-gcc-switches  ```


Upvotes: 34

Views: 32127

Answers (4)

samme4life
samme4life

Reputation: 1203

Setting up GO111MODULE env variable to off solved it for me. I'm using zsh. Here's the command I have put in my .zshrc file,

export GO111MODULE=off

My working environment: macOS Big Sur, Go version: 1.16

Upvotes: 56

Coconut
Coconut

Reputation: 2222

Since Go 1.15, go get by default will download source codes inside $GOPATH/pkg/mod/ (GOMODCACHE) which is in place of what it used to be $GOPATH/src/. (Ref: https://go.dev/doc/go1.15#go-command)

Turning off Go modules like GO111MODULE=off to download sources is a bad idea.

If you just need to download the sources, I strongly recommend you to use git clone instead.

$ git clone https://github.com/fatih/color

If you need to have it in $GOPATH/src/, just run:

$ git clone https://github.com/fatih/color $GOPATH/src/github.com/fatih/color

Please note that as of Go 1.14, Go projects are no longer confined to $GOPATH/src/ with support of Go modules. You don't really need that folder now. The $GOPATH/src/ folder was for dependency management before even Go modules were introduced.

Users are now advised to move to Go modules as https://github.com/golang/go/wiki/Modules states: "Since Go 1.14, module support is considered ready for production use, and all users are encouraged to migrate to modules from other dependency management systems".

Upvotes: 21

You can try this command.

export GO111MODULE=off
go get github.com/fatih/color

Upvotes: 5

dlsniper
dlsniper

Reputation: 7477

Go modules will hold the dependencies in $GOPATH/mod.

As such, when you'll import them into your project, you need to worry about two things: they are imported in a .go file and they are present in the go.mod file.

Once downloaded for a certain version, they will be available for all future projects.

If you want learn more about them and how they are organized, you can read the Go Modules Wiki available here https://github.com/golang/go/wiki/Modules

Upvotes: 13

Related Questions