Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go Get Not Downloading to SRC Folder

Tags:

go

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  ```


like image 605
ColonelKenny Avatar asked Feb 19 '21 20:02

ColonelKenny


People also ask

Where does go get install to?

Open the package file you downloaded and follow the prompts to install Go. The package installs the Go distribution to /usr/local/go. The package should put the /usr/local/go/bin directory in your PATH environment variable.

Is Gopath obsolete?

Since 1.12 version Go modules is enabled by default and the GOPATH will be deprecated in 1.13 version. For those who are getting started with Go 1.12, the installation and set up goes will be as follows.

Where does go get install binaries?

Much like the previous behaviour of go get , go install places binaries in $GOPATH/bin , or in $GOBIN if set.

How do you use go GET command?

Go The Go Command Go Getgo get downloads the packages named by the import paths, along with their dependencies. It then installs the named packages, like 'go install'. Get also accepts build flags to control the installation. When checking out a new package, get creates the target directory $GOPATH/src/<import-path> .


Video Answer


4 Answers

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

like image 194
samme4life Avatar answered Oct 14 '22 02:10

samme4life


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

like image 33
dlsniper Avatar answered Oct 14 '22 02:10

dlsniper


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".

like image 27
Coconut Avatar answered Oct 14 '22 01:10

Coconut


You can try this command.

export GO111MODULE=off
go get github.com/fatih/color
like image 5
Chiến Lê Tiến Avatar answered Oct 14 '22 02:10

Chiến Lê Tiến