Installing Golang in Alpine WSL

Callback Insanity
2 min readNov 6, 2021

Install the Go language:

sudo apk add gobash-5.1$ go
Go is a tool for managing Go source code.
Usage:go <command> [arguments]The commands are:bug start a bug report
build compile packages and dependencies
clean remove object files and cached files
doc show documentation for package or symbol
env print Go environment information
fix update packages to use new APIs
fmt gofmt (reformat) package sources
generate generate Go files by processing source
get add dependencies to current module and install them
install compile and install packages and dependencies
list list packages or modules
mod module maintenance
run compile and run Go program
test test packages
tool run specified go tool
version print Go version
vet report likely mistakes in packages
Use "go help <command>" for more information about a command.

Add the GOPATH environment variable to your .bashrc.

In my case my username is wsl. And the Go binaries are installed by default in $HOME/go/bin. So in my .bashrc I add:

export GOPATH=/home/wsl/go/bin
export PATH=$PATH:/home/wsl/.local/bin:$GOPATH

If I want to install an example module I have in Github globally, these are the steps:

git clone https://github.com/AlexanderAllen/names names
cd names
go mod init alexanderallen/names
# This will download any dependencies the module needs.
go mod tidy
# Test the compiled custom module:
go run .
vigilant-yonath
# This will install the custom module globally to the GOPATH:
go install
# To see what's available in the global GOPATH:
echo $GOPATH
/home/wsl/go/bin
ls -la $GOPATH
total 2056
drwxr-sr-x 2 wsl wsl 4096 Nov 6 21:52 .
drwxr-sr-x 4 wsl wsl 4096 Nov 6 21:52 ..
-rwxr-xr-x 1 wsl wsl 2095164 Nov 6 21:52 names

--

--

Callback Insanity

Organic, fair-sourced DevOps and Full-Stack things. This is a BYOB Establishment — Bring Your Own hipster Beard.