Golang for the C# Developer — [2] The Environment

Shonn Lyga
PoZeCode
Published in
2 min readFeb 18, 2017

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.

go-env-vars

*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:

  1. GOROOT — is the directory where your Go installation, docs, tools and Go standard library lives.
  2. GOPATH — is where you work, and where all your sources (and the sources you pull down) live. It is your workspace.
  3. 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.

GOROOT

When you install the Go MSI on windows, the default location will be set to c:\go.

GOPATH

Now that we can find our workspace on disk, the workspace itself must contain 3 directories as follows:

  1. src — that is where your source and dependencies live
  2. bin — that is the location of installed executables
  3. pkg — is where compiled files live

GOBIN

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.

See also:

Let me know if got anything wrong in the comments below.
Shonn.

--

--