In this article, we will show you how to install Golang on CentOS 8.
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software. It is a statically-typed, compiled, C-like programming language developed by Google.
Go's simplicity and versatility has made it to be the preferred language for developing high-performance web applications and microservices.
Prerequisites:
CentOS 8 Dedicated servers or KVM VPS
A root user access or normal user with administrator privileges.
Step 1. Keep you server up to date
yum update -y
Step 2. Download and extract Go 1.15.3
We will download Go using wget command and extract it in /usr/local path.
wget https://golang.org/dl/go1.15.3.linux-amd64.tar.gz
tar -zxvf go1.15.3.linux-amd64.tar.gz -C /usr/local
At the time of writing this guide, the latest available version was 1.15. You can check the latest Go version from the Go official download page.
Step 3. Setup Environment variables
The Go's runtime and build executables are now available under /usr/local/go/bin. Add the executable path to PATH environment variable. Add the GOROOT environment variable referencing your local Go installation. Use thesource command to reload the updated values.
echo 'export GOROOT=/usr/local/go' | sudo tee -a /etc/profile
echo 'export PATH=$PATH:/usr/local/go/bin' | sudo tee -a /etc/profile
source /etc/profile
Step 4. Verify the installation
To verify the installation, we can check the version of the Go by using following command:
go version
Output will show similar like:
go version go1.15.3 linux/amd64
Step 5. Write a Hello World application
We can write our first Hello World! program using following steps:
- Create a folder and navigate into it.
mkdir hello
cd hello
- Create a Go module using the go mod command.
go mod init hello
- Create a file named hello.go
touch hello.go
- Edit the file hello.go
vi hello.go
- Add following lines
package main
import "fmt"
func main() {
fmt.Printf("Hello World!")
}
Execute our first Go program using following command:
go run hello.go
Output:
Hello World!
We have successfully installed Golang on CentOS 8.
In this article, we have explained how to install Golang on CentOS 8
Top comments (0)