In this short article we will discuss how to install Go language on CentOS 8 operating system.
Go (often referred to as Golang) is a powerful and efficient programming language developed by Google. Since its release in 2009, Go has gained popularity for its simplicity, speed, and ability to handle concurrency effectively. In this article, we will explore the key features of Go, its advantages, and its use cases, as well as why it has become a favorite among developers worldwide.
Introduction to Go (Golang)
Go is an open-source, statically typed, compiled language designed to be easy to learn and use. It was created by Robert Griesemer, Rob Pike, and Ken Thompson at Google, with the primary aim of improving the development process and scalability of software projects. Go is inspired by C, but it incorporates modern language features and design choices to provide a more efficient and safer development environment.
Key Features of Go
- Simplicity: Go has a simple and clean syntax, making it easy for developers to read and write code. It avoids complex constructs and provides a smaller set of keywords and features.
- Concurrency: Go is built with concurrency in mind, offering goroutines, which are lightweight threads that enable easy management of concurrent tasks. Goroutines allow for efficient utilization of multi-core processors.
- Garbage Collection: Go has automatic memory management with garbage collection, relieving developers from manual memory management tasks.
- Fast Compilation: Go is compiled to machine code, and its compiler is remarkably fast, resulting in quick build times.
- Standard Library: Go comes with a robust standard library that includes essential packages for network programming, file I/O, encryption, and more.
- Cross-Platform Support: Go is designed to be portable, supporting various operating systems and architectures with ease.
Installing Go (Golang) On CentOS 8 Operating System
Installing Go (Golang) on CentOS is a straightforward process. We can use the official Go distribution or package managers like YUM (Yellowdog Updater, Modified) to install it, or by downloading Go archive file from Go official website. Here are the steps to install Go on CentOS 8 by using Go distribution :
Step 1: Update System Packages
Before installing any new software, it’s a good practice to update the system packages. Open a terminal and run the following command:
sudo dnf update
Step 2: Download and Install Go
Visit the official Go website (https://golang.org/dl/) and download the latest stable version of Go for CentOS. For example, we will download the binary release for CentOS 8, go1.20.6.linux-amd64.tar.gz
. By using wget command line we will submit following command line :
$ wget https://go.dev/dl/go1.20.6.linux-amd64.tar.gz
Output :
[ramans@otodiginet ~]$ wget https://go.dev/dl/go1.20.6.linux-amd64.tar.gz --2023-07-25 02:03:32-- https://go.dev/dl/go1.20.6.linux-amd64.tar.gz Resolving go.dev (go.dev)... 216.239.32.21, 216.239.38.21, 216.239.36.21, ... Connecting to go.dev (go.dev)|216.239.32.21|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://dl.google.com/go/go1.20.6.linux-amd64.tar.gz [following] --2023-07-25 02:03:35-- https://dl.google.com/go/go1.20.6.linux-amd64.tar.gz Resolving dl.google.com (dl.google.com)... 64.233.170.91, 64.233.170.136, 64.233.170.93, ... Connecting to dl.google.com (dl.google.com)|64.233.170.91|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 100214407 (96M) [application/x-gzip] Saving to: ‘go1.20.6.linux-amd64.tar.gz’ go1.20.6.linux-amd64.tar.g 100%[=======================================>] 95.57M 686KB/s in 53m 35s 2023-07-25 02:57:11 (30.4 KB/s) - ‘go1.20.6.linux-amd64.tar.gz’ saved [100214407/100214407]
Before doing next step, we will verify the file first by submitting command line :
$ sha256sum go1.20.6.linux-amd64.tar.gz
Output :
[ramans@otodiginet ~]$ sha256sum go1.20.6.linux-amd64.tar.gz b945ae2bb5db01a0fb4786afde64e6fbab50b67f6fa0eb6cfa4924f16a7ff1eb go1.20.6.linux-amd64.tar.gz
Step 3 : Extract The tarball File To /usr/local/bin Directory
Before extracting the tarball file, we must first check whether there is already Go installed on our system, if it is, we must remove it first. Extract the tarball file to the /usr/local directory using the tar command:
$ sudo tar -C /usr/local -xf go1.13.4.linux-amd64.tar.gz
Output :
[ramans@otodiginet ~]$ sudo tar -C /usr/local -xzf go1.20.6.linux-amd64.tar.gz [ramans@otodiginet ~]$ ls -ltr /usr/local/go/ total 52 -rw-r--r--. 1 root root 8 Jul 6 14:16 VERSION -rw-r--r--. 1 root root 419 Jul 6 14:16 SECURITY.md -rw-r--r--. 1 root root 1455 Jul 6 14:16 README.md -rw-r--r--. 1 root root 1303 Jul 6 14:16 PATENTS -rw-r--r--. 1 root root 1479 Jul 6 14:16 LICENSE -rw-r--r--. 1 root root 1339 Jul 6 14:16 CONTRIBUTING.md -rw-r--r--. 1 root root 52 Jul 6 14:16 codereview.cfg drwxr-xr-x. 11 root root 152 Jul 6 14:18 misc drwxr-xr-x. 3 root root 18 Jul 6 14:18 lib drwxr-xr-x. 2 root root 104 Jul 6 14:18 doc drwxr-xr-x. 2 root root 4096 Jul 6 14:18 api drwxr-xr-x. 26 root root 12288 Jul 6 14:18 test drwxr-xr-x. 49 root root 4096 Jul 6 14:18 src drwxr-xr-x. 2 root root 29 Jul 6 14:19 bin drwxr-xr-x. 4 root root 33 Jul 6 14:19 pkg
Step 4 : Setting Environment Variable
In this step, we will tell the system where to find the Go executable binaries by adjusting the $PATH. We 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):
[ramans@otodiginet ~]$ export PATH=$PATH:/usr/local/go/bin [ramans@otodiginet ~]$ source ~/.bash_profile
Step 5 : Verify Go
In this step we will verify Go, by querying its version. For this purpose we will submit the following command line :
$ go version
Output :
[ramans@otodiginet ~]$ go version go version go1.20.6 linux/amd64
Test Go (Golang) Installation
In this step, we will do the testing for Go installed on our system. To test whether Go is installed correctly, we will set up a workspace and build a simple “Hello world, Guys !” 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.
Conclusion
We have successfully installed Go on CentOS. Now, we can start developing Go applications and take advantage of its simplicity, performance, and powerful concurrency support. Remember to check for updates and new releases regularly to keep our Go installation up-to-date with the latest features and bug fixes. Enjoy coding in Go!