Learning Golang has been interesting. One of the basic setup secrets I don’t see talked about very much. However, an instructor on Go (over at Udemy) showed that if you setup your go environment properly you’ll be able to pulldown github repos, build and install binaries into the appropriate folders.
After installing Go on your OS, go to the terminal and run:
You’re looking for the GOPATH. Mine is:
Go to that folder in your path and create the following sub folders:
Within the src folder we’ll make a sub folder:
Once done, if you do a go get github.com/link_to_someones_repo
it will download the repo into the ../go/src/github.com/[git username of repo you pulled]
Build vs. Install
In Go you compile your apps for the target system the app will run on, as there’s no JVM (or similar technology) in Go.
If you do a: go build (while inside the code directory) it will build out a binary (exe for example) in the folder.
However, if you run: go install it will compile the binary but place it in your GOPATH / bin
What’s nice about go install, is that the /bin folder in Go is on the PATH, so you can execute your new binary from any location on the system.
For those executables created with go build, you can clean up your workspace with: go clean and all the binaries created (but not installed) will be removed.