Go, often called golang, is a modern open source programming language created by Google that allows you to build real-time and efficient applications.
Many popular applications, such as Kubernetes, Docker, Prometheus and Terraform, are written in Go.
This tutorial explains how to download and install Go on CentOS 8.
At the time of writing this article, the latest version of Go is 1.13.4. When we download the installation package, please visit Go official download page, and check if there is a new version available.
Execute the following command on CentOS 8 to download and install Go:
wget
or curl
tool to download Go binary installation package:wget https://dl.google.com/go/go1.13.4.linux-amd64.tar.gz
sha256sum go1.13.4.linux-amd64.tar.gz
Please make sure that the hash value output by the sha256sum
command is the same as the hash value of the download page.
692 d17071736f74be04a72a06dab9cac1cd759377bd85316e52b2227604c004c go1.13.4.linux-amd64.tar.gz
tar
command to extract the compressed package to the /usr/local
directory:sudo tar -C /usr/local -xf go1.13.4.linux-amd64.tar.gz
The above commands must be executed as root or a user with sudo privileges.
$PATH
environment variable to tell users where to find Go executable programs.You can add the following lines to the /etc/profile
file (system installation) or $HOME/.bash_profile
file (current user installation).
export PATH=$PATH:/usr/local/go/bin
Save the file and use the source
command to load the new PATH
environment variable into the current shell session.
source ~/.bash_profile
that's it. At this point, Go has been installed on your CentOS system.
In order to test if your Go is installed correctly, we will set up a workspace and build a simple "Hello World" program.
GOPATH
environment variable. By default, it is set to $HOME/go
. Run the following command to create this directory:mkdir ~/go
src/hello
in the workspace:nano ~/go/src/hello/hello.go
Paste the following code in the file:
package main
import"fmt"
func main(){
fmt.Printf("Hello, World\n")}
~/go/src/hello
, and execute the go build
command to compile the code:cd ~/go/src/hello
go build
The above code will build an executable program called hello
.
. /hello
If you see the following output, you have successfully installed Go.
Hello, World
Now that you have downloaded and installed Go, you can start writing your Go code.
Recommended Posts