Monday, November 12, 2018

Learn Golang tutorials - Install and setup Go language on Windows

In this blog post, We are going to learn an easy way to install go language on windows.
Golang installation on windows

Go Language installation 

Go is a modern popular opensource programming language. Go language is developed by Google. It provides binary versions for Windows, MacOS, and Linux officially. If you want to install different environment, You can get the source code and built it to your platform.
Go language provides the following binaries for installation on different environments
  • Windows
  • Apple MacoOS
  • Linux
  • Ubuntu

Installation and Setup on Windows

First get the binary installer for windows ie MSI file from and download it. It downloads MSI file

Once the download is completed, Install MSI file and select A:\Golang location  follow the next steps

Next step is to configure environment variables

Configure Environment Variables

Go to My Computers or This PC --> properties --> Advance System Settings --> Environment Variables, Create a System variable or environment variable GO_ROOT
give the value of  GO_ROOT to A:\Golang folder
Next, configure GO_ROOT to PATH variable ie set PATH to %PATH%\%GO_ROOT%\binary
This installs the Go Language successfully

Check Golang Installation 

To check the installation, first Open command line shell and give "go version" command, This gives go language version correctly

C:\>go version
go version go1.11.2 windows/amd64

C:\Users\Kiran>go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Kiran\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\Kiran\go
set GOPROXY=
set GORACE=
set GOROOT=A:\Golang
set GOTMPDIR=
set GOTOOLDIR=A:\Golang\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\Kiran\AppData\Local\Temp\go-build682765038=/tmp/go-build -gno-record-gcc-switches

Create a First sample Program 

using any IDE or editor, Write the first program and save this file as "First.go" package main
package main
import "fmt"

func main() {
    fmt.Printf("Hello, World")
}
To compile First.go file, Use go build command

A:\Golang\work>dir
 Volume in drive A is Work
 Volume Serial Number is C682-8F53

 Directory of A:\Golang\work

12-11-2018  14:54    <DIR>          .
12-11-2018  14:54    <DIR>          ..
12-11-2018  14:49                83 First.go
               1 File(s)             83 bytes
               2 Dir(s)  125,885,014,016 bytes free

A:\Golang\work>go build First.go

A:\Golang\work>dir
 Volume in drive A is Work
 Volume Serial Number is C682-8F53

 Directory of A:\Golang\work

12-11-2018  14:54    <DIR>          .
12-11-2018  14:54    <DIR>          ..
12-11-2018  14:54         1,969,152 First.exe
12-11-2018  14:49                83 First.go
               2 File(s)      1,969,235 bytes
               2 Dir(s)  125,883,043,840 bytes free

A:\Golang\work>
Execute the First.exe file by following command

A:\Golang\work>First.exe
Hello World 

Related article


EmoticonEmoticon