The simplest Go program you can start with.

· go  · 1 min read

Go simplest example

The simplest Go program you can start with.

Go has a lot of momentum nowadays, and we start to see a lot of job ads about this language, so let’s try the simplest possible example.

Install go

Go to the Go official installation documentation and proceed.

Check installation in your terminal with

~/workspace/$ go version
go version go1.18.1 linux/amd64

Create a folder and one file

Still inside the terminal? type

~/workspace/$ mkdir hellogo && cd hellogo
~/workspace/hellogo/$

Write your first golang program!

Create a file example.go inside directory hellogo, and we will only borrow the sample from official getting started guide here.

package main

import "fmt"

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

Ok! Even if you don’t know the Go langage, you should be pretty confident about what it’s doing ;)

Press the launch button

Ok it’s time to run the program.

Back in your terminal, type

~/workspace/hellogo/$ go run example.go
Hello, World!

Summary

We managed to create a example, that is even simpler than the official docs. If you really start with coding, maybe it’s the good time to restart from scratch and follow the official guide, that handle the modules part.

Enjoy!

Share:
Back to Blog

Related Posts

View All Posts »