Installing go lang

On Windows

  1. Download the latest version of go MSI installer from best suited for your system architecture.
  2. Start the installation by double-clicking on the installer and installer wizard will open as given in the following figure.
  3. For the installation follow the wizard instructions.
  4. Note that when you installing go lang using installer then it will ask the location where go will be installed as shown in the figure below.
  5. Installation directory of go lang is called GOROOT here the GOROOT is c:\go directory.
  6. After this follow the wizard instructions and complete the go lang installation.

Test Go installation

  1. To Check that Go is installed correctly or not, you need to create a go workspace (a place /folder/directory in which you save you go programs) and create a sample go program and run the program using the command line. The sample program is given below...
  2. You can create a sample program by using any simple text editor like notepad, notepad++, sublime or anyone you like and save the program in a workspace with the extension .go. 
  3. We suppose that the sample program is saved with hello.go
package main
import "fmt"
func main() {
fmt.Print("Hello go lang")

Running go program

  1. To run the go program you need to set up the GOPATH environment variable with your workspace path.
  2. Default go path is $HOME/go, Where $HOME is the environment variable or path which refers to users home directory, For example: if my window current username is Mahesh then $HOME refers to C:\Users\Mahesh by default. So the default GOPATH will be C:\Users\Mahesh\go.
  3. If you want to change the GOPATH then Visit (Right click on This PC (My Computer) > Properties > Advance system setting > Environment Variables). This will open a popup as shown in the figure below. This popup has two sections, the top section is for current users which are for logged in users and the bottom section is for all users of the system. you can create your environment variable in any section based on the permission you want to allow.
  4. To create a new environment variable click on the New button, then Name the environment variable is GOPATH and value is Your workspace path and then click ok to close the popup and save the settings.
  5. If GOPATH is already existed you can edit the GOPATH environment variable.
  6. After setting the environment variable, open the command prompt (User Window + R > Type CMD).
  7. Then switch your location with your workspace.
  8. Then compile the program by using go build hello.go (hello.go is the program name. Successful compilation with generate hello.exe in the same directory.
  9. To run the go program, run hello.exe by typing hello or hello.exe on cmd.
  10. Alternatively, you can run go program directly with go run hello.go. This will automatically compile and run the go program. 


Popular posts from this blog

Program to calculate telephone bill

Arrays in C Language

Program to check a year is leap year or not.

Sum of two numbers in go lang

String in golang


Pointers in C Language

Data types in Java

Decision Making in Go lang