ZNHOO Whatever you are, be a good one!

golang

  1. Installation
    1. macOS
  2. GOPATH

The terminologies "Go" and "golang" might be used interchangeably throughout this post.

Installation

macOS

We can install golang via brew or officially built binary package.

To install or upgrade golang with brew.

~ $ brew install go|golang

~ $ type go
go is hashed (/opt/homebrew/bin/go)
~ $ go version
~ $ go env

~ $ brew upgrade go|golang

For the second method, just download and click the binary (e.g. go1.23.3.darwin-arm64.tar.gz). It will prompts us to install golang in the system directory /usr/local/go, for all users. For update, just repeat the same process.

~ $ type go
go is hashed (/usr/local/go/bin/go)

GOPATH

The variable GOPATH is a pathname for installing extra modules beyond the official ones, usually residing in the user's home. It is also the place where we develop and test personal modules.

~ $ go env GOPATH
/Users/zachary/go

~ $ echo $GOPATH

~ $ ls go/bin/
go-wrk

Interestingly, it is not a Shell environment variable, but exclusive to golang! Upon installation, the golang toolchain would automatically configure it, including the GOPATH/bin. We can manually configure it for Shell reference.

# ~/.bash_profile

export GOPATH="${HOME}/go"
PATH="${GOPATH}/bin:$PATH"