Installing golang on Rocky Linux
 golangPerhaps more for my benifit but here lies instructions to install golang on a Raspberry PI running Rocky Linux.
Installing
sudo dnf install -y tar curl
For me, Rocky 9 on the PI did not come with tar pre-installed. Make sure you have these two tools available:
sudo dnf install -y \
curl \
tar
Download the binary from the official golang site:
$ curl https://go.dev/dl/go1.20.2.linux-arm64.tar.gz --output /tmp/go.tar.gz --location
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 75 100 75 0 0 72 0 0:00:01 0:00:01 --:--:-- 73
100 91.0M 100 91.0M 0 0 14.4M 0 0:00:06 0:00:06 --:--:-- 18.9M
For those unfamiliar with
curl
:
--output /tmp/go.tar.gz
tellscurl
to put the binary at the given filepath--location
tellscurl
to follow redirects
Verify the checksum matches the expected value on https://go.dev/dl/:
$ sha256sum /tmp/go.tar.gz
78d632915bb75e9a6356a47a42625fd1a785c83a64a643fedd8f61e31b1b3bef /tmp/go.tar.gz
Extract the contents to /usr/local/go
:
tar -zxvf /tmp/go.tar.gz -C /usr/local
Add go to the path on boot:
echo 'export GOROOT=/usr/local/go' | tee -a /etc/profile.d/golang.sh
echo 'export PATH=$PATH:/usr/local/go/bin' | tee -a /etc/profile.d/golang.sh
echo 'export PATH=$PATH:$(go env GOPATH)/bin' | tee -a ~/.bash_profile
Apply those changes:
source /etc/profile.d/golang.sh
source ~/.bash_profile
Check the installation was successful and the go command is discoverable on the path.
$ go version
go version go1.20.2 linux/arm64
Some go libraries require a C compiler, this can be added with:
dnf install gcc-c++
Upgrading
Repeat the curl
through tar
extraction stage with the link of the new version. Simple.
Uninstalling
Clean-up cached files:
go clean -modcache
go clean -cache
go clean -fuzzcache
Remove the env var configurations:
rm /etc/profile.d/golang.sh
sed -i '/go env/d' ~/.bash_profile
A restart is required to reset the env vars that have been changed.
Finally remove the golang binaries:
rm /usr/local/go -r