The first step towards mastering the Go language is to install the Go compiler in your system. Go compiler can be installed on different types of systems like Windows, Linux, and Mac, etc. You can download the Go software for the corresponding platform from https://golang.org/dl/.
Go installation in Windows
Installing Go in the Windows system is very straightforward. Below are the steps:
- Download the
.msi
file from https://golang.org/dl/. - Double click to start the installation and follow the prompts.
- By default, this will install into the folder
C:\Program Files\Go\
; you can change the path as you wish. You need to set the Go root environment variable to your chosen path. I am installing in the pathC:\Go
. - Next, add the bin subdirectory of your Go root (for example,
C:\Go\bin
) to your PATH environment variable.
Go installation in Mac
- Download the required
.pkg
file from https://golang.org/dl/. - Double click on the downloaded file to start the installation. Follow the prompts to complete the installation process.
- This will install the package into
usr/local/go
directory by default. - Go root path in this case will be
/usr/local/go/bin
. Go automatically add the GO path to the environment variable.
Go installation in Linux
- Download the zip file (.gz) file from the download page i.e. https://golang.org/dl/.
- And unzip and untar the file to
/usr/local
. - Now, add
/usr/local/go/bin
to the PATH environment variable. You can use the following command.
export PATH=$PATH:/usr/local/go/bin
Verify the Go installation
To check if the Go has been installed successfully, type the command go version
in the terminal and it will show the installed Go version. Here is the output in my terminal.
C:\Users\hp>go version
go version go1.16.5 windows/amd64
go version go1.16.5 windows/amd64
go1.16.5
was the Go version when I installed and writing this tutorial. This indicates that Go has been successfully installed.
In the next tutorial, we will write our first program and execute it.