Skip to content

Golang

Install

apt install golang

Export GOPATH env var:

echo 'export GOPATH="$HOME/golang"' >> ~/.bashrc

Add

echo 'export PATH="$PATH:${GOPATH}/bin/"' >> ~/.bashrc

Usage

Using external modules

go mod init grabana
go mod tidy
go run ./main.go

Build an existing project

go build

Install package system-wide

go get github.com/prometheus/prom2json/cmd/prom2json

Install latest git master

Install all deps:

go get -d ./...

Run single file

go run test_hello_world.go

Handle multiple go versions

Natively

Install go

go install golang.org/dl/go1.19.1@latest
rehash
go1.19.1 download
alias go=go1.19.1
go version

goenv

Issues:

Stale goenv alternatives