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

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.

About Shonn Lyga

Obsessed with anything and everything in Software Engineering, Technology and Science
This entry was posted in Go, Golang, Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s