Go - northwood-labs/macos-for-development GitHub Wiki
Go
Go (sometimes called Golang) is a fast, compiled, garbage-collected, functional programming language. It has built-in support for concurrency and asynchronous programming, and can cross-compile easily to multiple operating systems and CPU architectures.
It is a remarkably stable language, and upgrades tend to be quite uneventful (this is a good thing). It is a “batteries-included” environment with compiling, testing, fuzzing, profiling, and dependency management all built-in.
Unless there is a specific bug in the latest release that we want to avoid (quite rare), we should always plan to run the latest release.
-
Install the Go toolchain.
brew install go -
Add
$GOPATH/binto your$PATHenvironment variable. By default (i.e., without configuration),$GOPATHis defined as$HOME/go.export PATH="$PATH:$GOPATH/bin"
Version management
Generally speaking, always run the latest release. Having said that, there is occasionally a case where software needs to be updated for the latest release (usually a .0 release), and that hasn't happened yet, so we need to roll back.
Managing Go installations
Go has a built-in way of installing a specific version of Go. This approach results in a go binary with the version in the name.
go install golang.org/dl/go1.22.7@latest
go1.22.7 download
go1.22.7 version
If you are wrapping your Go calls in a Makefile, you can redefine $(GO) with:
GO=$(shell which go1.22.7)
Goenv
goenv is a port from pyenv, and they work nearly identically.
-
Install
goenv.brew install goenv -
Add
eval "$(goenv init -)"to your profile. -
Restart your shell.
-
Install a specific Go version and set it to the default for this project.
goenv install 1.22.7 goenv rehash goenv local 1.22.7 goenv version
Package management
Go modules
go mod init {URL}
go get entgo.io/ent@latest
go mod tidy