Getting Started Guide: Introduction to Go Programming on Linux

Table of Contents

  1. Overview
  2. Installation - Ubuntu/Debian - Arch Linux - SUSE - Red Hat - From Official Source Code
  3. Hello World
  4. Conclusion

Overview

Welcome to the “Get You Started Guide: Introduction to Go Programming on Linux.” This tutorial is designed to help beginners get started with Go (Golang) programming on Linux systems. By the end of this tutorial, you will have a solid understanding of how to set up a Go development environment, write a basic “Hello World” program, and execute it successfully.

Before proceeding with this tutorial, it is recommended that you have some basic knowledge of Linux operating systems and programming concepts. Additionally, you will need access to a Linux system for the installation and hands-on exercises.

Installation

Ubuntu/Debian

To install Go on Ubuntu or Debian-based systems, you can use the native package manager:

sudo apt update
sudo apt install golang

Arch Linux

On Arch Linux, you can install Go using the following command:

sudo pacman -S go

SUSE

To install Go on SUSE, you can use the Zypper package manager:

sudo zypper install go

Red Hat

On Red Hat-based systems, such as CentOS or Fedora, you can use the YUM package manager:

sudo yum install go

From Official Source Code

If you prefer to install Go from the official source code, follow these steps:

  1. Visit the official Go Downloads page.
  2. Download the tarball for your system architecture.

  3. Extract the tarball:

     tar -C /usr/local -xzf go{x.x.x}.linux-amd64.tar.gz
    
  4. Set the Go environment variables:

     export PATH=$PATH:/usr/local/go/bin
     export GOPATH=$HOME/go
     export PATH=$PATH:$GOPATH/bin
    

    Note: Replace {x.x.x} with the actual version number.

Hello World

Now that you have Go installed on your Linux system, let’s write a simple “Hello World” program.

Create a new file called hello.go using any text editor:

nano hello.go

Add the following code to the hello.go file:

package main

import "fmt"

func main() {
    fmt.Println("Hello, World!")
}

Save the file and exit the text editor.

To compile and run the program, execute the following command:

go run hello.go

You should see the following output:

Hello, World!

Congratulations! You have successfully written and executed your first Go program.

Conclusion

In this tutorial, you learned how to install Go on various Linux distributions, including Ubuntu/Debian, Arch Linux, SUSE, and Red Hat. Additionally, you wrote a simple “Hello World” program and executed it successfully.

Now that you have a basic understanding of Go programming, you can explore more advanced topics and create more complex applications using the Go language.

Happy coding!