DEV Community

Krishna Tej Ch
Krishna Tej Ch

Posted on • Originally published at chkrishnatej.com on

Go Lang Installation

Prerequisutes


go supports a wide range of operating systems. There are two ways go can be installed on the system.

  • Binaries
  • Building it from the source

I am installing it on MacBook Pro with macOS Mojave v10.14.4 for this tutorial using the Mac binaries.

You could get the download link here

golang download page

As shown in the image above, select the relevant package accoridng to the operating system. I have downloaded the one for Apple macOS.

  • Download file golang download page

Installation


The installation is a fairly straight. You could go with the defaults as shown below.

golang installation step1

golang installation step2

golang installation step3

golang installation success

Verification


To verify if the go has been successfully, it can be verified from the command line

You could use the following commands in the terminal to verfiy.

>>> which go # Returns path where go is installed/usr/local/go/bin/go>>> go version # Returns the version of the go installedgo version go1.12.4 darwin/amd64

golang installation success verification

If the terminal shows up as the above, then go lang has been successfully installed.

Setting up workspace


Go follows a different approach to manage the code which requires to setup the project workspace. This means all the go projects should be developed and maintained in the defined workspace.

Steps to setup the workspace


Open the shell config which is locate in the HOME directory.

NOTE:

  • bash_profile or .bashrc for BASH

- .zshrc for Oh my Zsh!

Add the following variables to shell config

>>> export GOPATH=$HOME/<go-workspace> # <go-workspace> is a filler. Fill it with proper path>>> export PATH=$PATH:$GOPATH/bin>>> export GOROOT=/usr/local/opt/go/libexec>>> export PATH=$PATH:$GOROOT/bin
  • $GOPATH/src : Go Projects source code
  • $GOPATH/pkg : Contains imported packages
  • $GOPATH/bin : The compiled binaries home

This completes the setup of go. And system is ready for some code.

Top comments (2)

Collapse
 
rbo13 profile image
Richard Burk

Nice article, Krishna! Some things to consider, if you are running the latest version of Go, $GOPATH is not necessary since we have GOMODULES! Yaaay πŸ₯³πŸŽ‰ however, GOMODULES is not enabled by default, you need to set your environment variable to export GO111MODULE=on See this blog post for more information blog.golang.org/using-go-modules.

Collapse
 
chkrishnatej profile image
Krishna Tej Ch

Thanks for pointing out, Richard. I'll update the post shortly. πŸ™‚