Go, often referred to as Golang, is an open-source programming language developed by Google. It is widely used for its simplicity, efficiency, and robust concurrency support. This guide will walk you through the steps to install Go on your AlmaLinux 8.10 system.
Prerequisites
Before you begin, ensure you have:
- A running AlmaLinux 8.10 system
- A user account with sudo privileges
- Internet connectivity to download necessary packages
Step 1: Update Your System
First, update your system to ensure all existing packages are up to date.
$ sudo dnf update -y
Step 2: Download Go Binary
Visit the official Go downloads page to find the latest version of Go. You can use wget
to download the Go tarball directly.
$ wget https://golang.org/dl/go1.20.3.linux-amd64.tar.gz
Replace go1.20.3.linux-amd64.tar.gz
with the version you want to install.
Step 3: Extract the Archive
Extract the downloaded tarball to the /usr/local
directory.
$ sudo tar -C /usr/local -xzf go1.20.3.linux-amd64.tar.gz
Step 4: Set Up Go Environment
Next, you need to set up the Go environment variables. Add the following lines to your shell profile file (~/.bashrc
, ~/.zshrc
, etc.) to set up the Go environment variables.
$ echo "export PATH=$PATH:/usr/local/go/bin" >> ~/.bashrc
$ source ~/.bashrc
This adds Go’s binary directory to your system’s PATH
, enabling you to run Go commands from any terminal session.
Step 5: Verify the Installation
To verify that Go has been installed correctly, check its version.
$ go version
You should see output similar to:
$ go version go1.20.3 linux/amd64
Step 6: Create a Go Workspace
Go encourages a specific workspace structure. By default, your Go workspace should be in your home directory. Create a directory named go
and subdirectories for your Go projects.
$ mkdir -p ~/go/{bin,src,pkg}
-
src
: contains your Go source files -
pkg
: contains package objects -
bin
: contains executable commands
Step 7: Write a Simple Go Program
To verify that everything is working correctly, you can create and run a simple Go program. First, create a new directory for your project:
$ mkdir -p ~/go/src/hello
$ cd ~/go/src/hello
Create a new Go file named hello.go
and add the following content:
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
Save and exit the text editor.
Step 8: Build and Run the Go Program
Navigate to your project directory and use the go run
command to build and run your program.
go run hello.go
You should see the output:
Hello, World!
Conclusion
You have successfully installed Go on your AlmaLinux 8.10 system. Go is now ready for you to start developing your applications, taking advantage of its powerful features and efficient performance. For more detailed configurations and advanced usage, refer to the official Go documentation.
Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.