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 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.20.4
Release : 1.module_el8+433+1910a33d
Architecture: x86_64
Install Date: Sat 19 Aug 2023 09:49:08 PM UTC
Group : Unspecified
Size : 0
License : BSD and Public Domain
Signature : RSA/SHA256, Wed 31 May 2023 03:37:09 PM UTC, Key ID 05b555b38483c65d
Source RPM : go-toolset-1.20.4-1.module_el8+433+1910a33d.src.rpm
Build Date : Wed 31 May 2023 03:10:29 PM UTC
Build Host : x86-04.stream.rdu2.redhat.com
Relocations : (not relocatable)
Packager : [email protected]
Vendor : CentOS
Summary : Package that installs go-toolset
...
Option 2) Install Go 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.21.0 to /root/.go
This may take a bit of time...
Downloaded!
Setting up GOPATH
GOPATH has been set up!
One more thing! Run `source /root/.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.21.0 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<<EOF
package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}
EOF
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.