Are you looking for an easy way to install Go (Golang) on CentOS 8 / RHEL 8?. Go or Golang is an open source programming language designed to ease the Development of reliable, simple, and efficient applications.
RHEL 8 doesn’t come with Go pre-installed but you’ll have to download and install the package from RHEL 8 upstream repositories. The process is simple enough that it doesn’t require good understanding of Linux and Red Hat system.
Linux Mint: How to Install Go (Golang) on Linux Mint
For Ubuntu refer to: How to Install latest Go on Ubuntu
Option 1) Install Go on CentOS 8 / RHEL 8 from AppStream repo
You can confirm the availability of Go on RHEL 8 by running the command below.
sudo yum module list go-toolset
The package has the name “go-toolset“. Install Go on RHEL 8 using:
sudo yum module -y install go-toolset
Confirm the RPM package details:
$ rpm -qi go-toolset
Name : go-toolset
Version : 1.16.12
Release : 1.module+el8.5.0+720+c057d5cf
Architecture: x86_64
Install Date: Fri Apr 15 10:19:32 2022
Group : Unspecified
Size : 0
License : BSD and Public Domain
Signature : RSA/SHA256, Wed Dec 15 17:57:49 2021, Key ID 15af5dac6d745a60
Source RPM : go-toolset-1.16.12-1.module+el8.5.0+720+c057d5cf.src.rpm
Build Date : Wed Dec 15 17:40:03 2021
Build Host : ord1-prod-x86build001.svc.aws.rockylinux.org
Relocations : (not relocatable)
Packager : [email protected]
Vendor : Rocky
Summary : Package that installs go-toolset
Description :
This is the main package for go-toolset.
Option 2) Install Go on CentOS 8 / RHEL 8 using installer_linux
Remove Go installed using module
sudo yum module -y remove go-toolset
Download installer with wget to your local system.
wget https://storage.googleapis.com/golang/getgo/installer_linux
After downloading the file, make it executable:
chmod +x ./installer_linux
And lastly run the installer from your current terminal shell.
$ ./installer_linux
Welcome to the Go installer!
Downloading Go version go1.18.1 to /home/jmutai/.go
This may take a bit of time…
Downloaded!
Setting up GOPATH
GOPATH has been set up!
One more thing! Run source /home/jmutai/.bash_profile to persist the new environment variables to your current session, or open a
new shell prompt.
Source the ~/.bash_profile
to start using Go environment variables in your current session.
$ source ~/.bash_profile
$ go version
go version go1.18.1 linux/amd64
Test Go installation on CentOS 8 / RHEL 8
Now that we have Go installed on RHEL 8, let’s test to ensure it is working.
Start by creating your workspace directory.
mkdir $HOME/go
Create a directory inside it to host a test Go application.
cd $HOME/go
mkdir -p src/helloworld
cd src/helloworld
Create a file named helloworld.go
that looks like:
tee helloworld.go<
Build the application with go tool
go build
This will generate a new file called helloworld
.
$ ls
helloworld helloworld.go
Execute the file by running.
$ ./helloworld
hello, world
To install the binary into your workspace’s bin directory, use:
$ go install
$ ls ~/go/bin/
helloworld
To remove it use:
go clean -i
You can add your Go binary directory to $PATH
.
$ vim ~/.bashrc
export PATH="$PATH:~/go/bin/"
You have installed Go on RHEL 8 / CentOS 8. Enjoy developing Go applications on your RHEL workstation.