Golang, also shortened as Go, is a free and open-source statically typed programming language that focuses on simplicity, efficiency, and reliability. It was originally developed for applications related to infrastructure and networking and was intended to replace server-side apps such as C and Java.
Over time, Go has become hugely popular. It is used to write command-line tools and is widely used in artificial intelligence, cloud-based, and server-side applications. However, Go really performs the best when it comes to infrastructure. Some of the popular DevOps tools such as Kubernetes and Docker.
In this short guide, we will explore how you can install Go in Alpine Linux.
Prerequisites
Before you get started, ensure that you have an instance of Alpine Linux installed with SSH access.
Installing Go in Alpine Linux
To get off the ground, log in to your Alpine instance and add community repositories as shown.
cat > /etc/apk/repositories << EOF; $(echo) https://dl-cdn.alpinelinux.org/alpine/v$(cat /etc/alpine-release | cut -d'.' -f1,2)/main/ https://dl-cdn.alpinelinux.org/alpine/v$(cat /etc/alpine-release | cut -d'.' -f1,2)/community/ https://dl-cdn.alpinelinux.org/alpine/edge/testing/ EOF
Next, install Go and other essential packages as follows.
# apk add --update --no-cache go vim git make musl-dev curl
Once that is done, export the following variables as follows.
export GOPATH=/root/go export PATH=${GOPATH}/bin:/usr/local/go/bin:$PATH export GOBIN=$GOROOT/bin mkdir -p ${GOPATH}/src ${GOPATH}/bin export GO111MODULE=on
With that out of the way, verify that Go is successfully installed:
$ go version
Creating a Simple Go Program
To test our Go installation, we will create a simple Go program using the vim editor as shown.
$ vim hello.go
We will then write the following lines of code. The code simply prints a simple message to stdout. Feel free to paste the code into your editor.
package main import "fmt" func main() { fmt.Printf("Hello guys, welcome to Go Programming\n") }
Save the changes and exit.
Then run the Go application as follows.
$ go run hello.go
This is a confirmation that Go has successfully been installed. And there you go. We have successfully installed Go on Alpine Linux.