.:: mkdevs.eu ::.

First steps with GO

Goals

At the end of this article you'll known how to:

Let's GO

Install GO

The best way is simply to use the Download and install steps from golang website.

Personally, I prefer to install go only for my user.

$ rm -rf ~/.local/go && tar -C ~/.local -xzf go1.24.4.linux-amd64.tar.gz
$ ln -s ~/.local/go/bin/go ~/.local/bin/go

and I always add in my .bashrc file the folowwing lines.

if [ -d ~/.local/bin ]; then
    export PATH=$PATH:~/.local/bin
fi

Now, you can playing with GO.

Write your first go app

Go to you sandbox or whatever working directory and create a hello sub directory

$ mkdir hello
$ cd hello

Then, enable dependency tracking for your code

$ go mod init learn/hello
go: creating new go.mod: module learn/hello

Using your favorite text editor, create a file hello.go in which to write your code.

Paste the following code into your hello.go file and save the file.

package main

import "fmt"

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

Finally, Run your code to see the greeting.

$ go run .
Hello, World!