How to check the Golang version on Mac

To check if Go is installed on your system, you can run the following command:

$ go

If there is no error and the mouse pointer keeps blinking, then it means a version of Go is indeed installed on your system.

Version

To find out what version of Go is installed, you need to run Go with the version flag version:

$ go version

This will tell you the version of Go installed on your system.

Installation

Firstly, you must download the latest official Golang release, which you can find right here. Or, you can run the following curl command to download the required package:

$ curl -o golang.pkg https://dl.google.com/go/go1.16.4.darwin-amd64.pkg 

Now, to install the Go distribution, run the following command:

$ sudo open golang.pkg

This will open the Go installation wizard. Follow through with the wizard instructions to complete your installation.

Setup

Now that you have installed the Go release on your system, you need to set environment variables. Running the following three commands will set the required environment variable paths:

$ export GOROOT=/usr/local/go 
$ export GOPATH=$HOME/Projects/Proj1  
$ export PATH=$GOPATH/bin:$GOROOT/bin:$PATH 

With this, you have successfully installed and set up your Go workplace. Check if everything is working properly by checking the version, using the following command:

$ go version
Copyright ©2024 Educative, Inc. All rights reserved