Installing go and understanding GOPATH and GOROOT

Posted on September 08, 2020  -  1 min read

Hey folks

To start with the series, Let’s see how to install Go in your system.

Visit Go Downloads and download Go for your respective OS platform.

After installing, you can try

go version

Understanding GOPATH and GOROOT

You can run go env to get all the environment variables.

By default, Go will be installed in your home directory. It is also advisable to install it in home directory than other locations.

GOROOT

GOROOT is the location where all the Go language source code is present. This is not our source code but the language itself, compiler and Go tools. This location is automatically set in the installation itself.

GOPATH

Go assumes the location is at $HOME/go.

This is the location where our source code lives and all third party packages live. When we run Go, the language searches for the source code in the provided location and executes it.

It’s possible to have multiple GOPATH locations but it’s recommanded to have one.

Hope you learned something.

Thank you for reading :)