[ad_1]
Go, often referred to as golang
is a modern open-source programming language created by Google that allows you to build reliable 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.
Downloading and Installing Go on CentOS 8 #
At the time of writing this article, the latest stable version of Go is version 1.13.4. Before downloading the tarball, visit the official Go downloads page
and check if there is a new version available.
Perform the following steps below to download and install Go on CentOS 8:
-
Download the Go binary using either the
wget
orcurl
utility:wget https://dl.google.com/go/go1.13.4.linux-amd64.tar.gz
-
Once the archive is downloaded, verify the tarball checksum by typing:
sha256sum go1.13.4.linux-amd64.tar.gz
Make sure the hash printed from the
sha256sum
command matches the one from the downloads page.692d17071736f74be04a72a06dab9cac1cd759377bd85316e52b2227604c004c go1.13.4.linux-amd64.tar.gz
-
Extract the tarball to the
/usr/local
directory using thetar
command:sudo tar -C /usr/local -xf go1.13.4.linux-amd64.tar.gz
The command above must be run as root or a user with sudo privileges
. -
Tell the system where to find the Go executable binaries by adjusting the
$PATH
environment variable.You can do this by adding the following line to the
/etc/profile
file (for a system-wide installation) or to the$HOME/.bash_profile
file (for a current user installation):~/.bash_profile
export PATH=$PATH:/usr/local/go/bin
Save the file, and load the new
PATH
environment variable into the current shell session using thesource
command:source ~/.bash_profile
That’s it. At this point, Go has been installed on your CentOS system.
Test the Installation #
To test whether Go is installed correctly, we will set up a workspace
and build a simple “Hello world” program.
-
The location of the workspace directory is specified with the
GOPATH
environment variable. By default, it is set to$HOME/go
. To create the directory
run the following command:mkdir ~/go
-
Inside the workspace create a new directory
src/hello
:mkdir -p ~/go/src/hello
In that directory create a file
namedhello.go
:nano ~/go/src/hello/hello.go
Paste the following code to the file:
~/go/src/hello/hello.go
package main import "fmt" func main() { fmt.Printf("Hello, Worldn") }
-
Navigate
to the~/go/src/hello
directory and rungo build
to build the code:cd ~/go/src/hello
go build
The command above will build an executable named
hello
. -
Run the executable by typing:
./hello
If you see the following output, then you have successfully installed Go.
Hello, World
Conclusion #
Now that you have downloaded and installed Go, you can start writing your Go code
.
If you hit a problem or have feedback, leave a comment below.
[ad_2]
Source link