How To Install Go in Linux Mint

Go, also known as Golang, is a programming language that was developed by Google in 2007 with the aim of simplifying systems programming and networked services. It comes with many features such as built-in support for concurrency, automatic memory management, and the ability to be easily compiled for multiple platforms. Its coding syntax resembles to C, but it also includes added benefits such as garbage collection and structural typing. Go is being utilized by a number of major companies and it’s getting famous day by day among developers for web server and microservices development.

Installing Go in Linux Mint is pretty easy as it’s already present inside it’s repository with exception to old versions of Linux Mint.

First open the terminal and type the following command with yes when prompted :

sudo apt update
sudo apt install golang

After the successful installation, you can the version of Go installed in your system by typing the following command 

go version

Next, we will run the first program in Go to test whether it is installed properly or not.

Fire up the terminal and open the nano editor with file name Hello.go. All Go files would have .go file extension.

nano Hello.go

Here we are going to write our first Go program which is going to print “Hello World” into the console. Just copy and paste the following program for testing.

package main

import "fmt"

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

In the above program, first we are declaring the package “main”. Which is a way to group all the functions in the main library. Next, importing the popular “fmt” package, which contains functions for formatting text, including printing to the console. This package is one of the standard library packages in Go. Then, we implement a main function to print a message to the console. A main function executes by default when you run the main package.

To save the contents of the file and exit the Nano text editor, press the “Ctrl” and “X” keys simultaneously.

Finally, to execute this program, you will need to add “run” flag with the file name. This will print the output into the Linux Mint console.

go run Hello.go

If you have just started with Go, you can check getting started tutorial here, https://go.dev/doc/tutorial/getting-started

Leave a Reply

Your email address will not be published.