TL;DR – The development environment of a Go developer is very different from that of C#. All Go source code lives in a single workspace, there is no GAC and your machine Environment Variables play a main role in locating code, tools and binaries.
*I strongly recommend using the official page for installation and configuration.
GOPATH vs. GOROOT vs. GOBIN
To set-up the Go environment, all we need to do is to configure 3 environment variable:
- GOROOT – is the directory where your Go installation, docs, tools and Go standard library lives.
- GOPATH – is where you work, and where all your sources (and the sources you pull down) live. It is your workspace.
- GOBIN – is where your executables will be placed after you install a go program form source by running ‘go install’.
Assuming you are a windows developer, you should remember that as opposed to .NET, there is nothing like the GAC or the use of the windows registry for dependencies resolution. Your dependencies get resolved via those 2 environment variables.
Also important to remember that while in c# we can dynamically load a .dll assembly at runtime, in Go there is only 1 compiled assembly with all the dependencies compiled into it from source.
When you install the Go MSI on windows, the default location will be set to c:\go.
Now that we can find our workspace on disk, the workspace itself must contain 3 directories as follows:
- src – that is where your source and dependencies live
- bin – that is the location of installed executables
- pkg – is where compiled files live
I personally set-up my bin folder like this: %GOPATH%\bin. That way my go tools and installed executables are all placed in one directory that is easy to find.
After installing Go and configuring the mentioned environment variables, you are all set to proceed to your first helloworld example.
Let me know if got anything wrong in the comments below.