as beginner, I’d like to know what’s the best practice to go with $GOPATH or $GO111MODULE. Does go get require $GOPATH set up so it will download all dependencies to $GOPATH directory?
Thanks
as beginner, I’d like to know what’s the best practice to go with $GOPATH or $GO111MODULE. Does go get require $GOPATH set up so it will download all dependencies to $GOPATH directory?
Thanks
If you use newer Go verison, let´s say the latest, forget about this. Use modules.
I am using latest verison, and get my GO111MODULE=on set up. My follow-up question is the go get still requires $GOPATH setup? I tried go get and looks like it download packages under directory as configured by $GOPATH.
Yes, go get
still requires GOPATH
.
You still need to setup GOPATH
not for the reason of development but rather maintaining the go get
binary distribution mechanism. Example to install golangci-lint go program, we still use:
$ go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
go.mod
file) instead. That also means you rarely use go get
except getting some go program installed out-of-the-box like (#2).Thanks @hollowaykeanho. some follow up quesitons.
if we use go get
to download an out-of-the-box program as in your example to GOPATH
directory, when we need this program, will GO automatically search it in GOROOT
as well as GOPATH
?
I think we can also use go get
to download packages or dependencies for our projects, since we’re using GO111MODULE
which typically don’t use GOPATH
directory, how GO know where to find these downloaded dependencies for our projects? Does GO also automatically search GOPATH
for any dependencies that we use for our project (which I don’t believe so)?
go get -u
, -u
here per my understanding means update which will send your local update to the github (for this example). Do we need -u if we don’t have any plan to update the github? I see folks use -u
most likely so just try to clarify a bit here
When you need to use the Go program like the given example, which is a powerful linter to check your go source codes. It will automatically search in GOPATH
. Any compiled binary is stored under GOBIN
, which is essentinally GOPATH/bin
.
Module uses a different mechanism to organize the dependency. As far as I understand, it is no longer using GOPATH (that was the goal). Module highly depends on go.mod
file’s require
clauses to provide the list of dependencies. For more info, I suggest you spend some times to read through these documentations and do a deep dive experimentation with some dummy repos:
1.Modules · golang/go Wiki · GitHub
2. Using Go Modules - The Go Programming Language
P/s: I’m still waiting for the instruction from the developers to finally let go of GOPATH
. As of to-date, I’m still having binary installations in my GOPATH
.
-u
argument put it simply, is to pull the latest from Github to your local repository and re-compile the corresponding binary (if any). It is not the other way round. Hence, the name update
, which stands for “update your local repo”.
To push from local repository to Github, you develop using your conventional way which is enter into the directory and git push
. (Can you feel our pain before go module, in the past just by reading that sentence? )
Even now I feel more pain not only these sentences but more the confusion between GOPATH
and GO111MODULE
Does go get
not only download the program but also do the compiling and put complied binary into $GOPATH/bin
as well?
since now I am using IDE goland and I assume these go tools
(can I view golangci-lint
as one of go tools
) are automatically taken care of by IDE, it’s even rare to use go get
. agree?
Yes, automatically. You get the source codes in GOPATH/src
and binary in GOPATH/bin
.
Beats me on go get
ting tools for programming Go. That depends on the IDE robustness. I can’t answer deeply on IDE part because I’m one of the outdated Linux vi
guy that still producing 80 max columns codes .
Nope. You still need to familiarize with go get
. It is just an easy, basic, and another way to distribute go program (those that has main
codes, like the very useful Hugo
). You still need it for cases like:
Tl.DR (4D):
GOPATH
and go with the flowgo get
Go is a very powerful tool. Let time nourish you. Welcome aboard, gopher!
You mentioned there is possibility to retire GOPATH
but looks like at least it’s needed for go get
working probably, so I assume there will be other way for go get
once we let it go of GOPATH
?
Thanks and your remarks are very inspiring!
I strongly believe the go get
command remain as the same for backward compatibility. Even in go1.13, it was upgraded instead of being replaced.
I’m expecting only the underlying GOPATH
mechanism will change. That will take some times because not everyone is onto module yet and it is not an easy task to make such transition.
Don’t worry. When it is time to drop GOPATH
, it will be a huge announcement.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.