Back to blog
Sep 02, 2024
2 min read

Getting Started with Go: Your First Program

Let's start your Go journey

In this post I will write how to create your first Go program. The famous Hello World, that I will replace world for Go.

To get started, you’ll need to install Go on your system. Go to https://go.dev/doc/install and follow the instructions for your operating system

Once installed, verify your installation by opening a terminal and running

go version

This should display the installed Go version.

Now, let’s write our first Go program. Create a file named hello.go with the following content:

package main

import "fmt"

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

Save this file and run this program using the command below in your terminal:

$ go run hello.go

You will see in your terminal the output: “Hello, Go!” Now, let’s break down the program to understand what it is happening:

  1. package main: Every Go file starts with a package declaration. The main package is special because it defines an executable program.

  2. import fmt: This imports fmt package, which provides formatting and printing functions.

  3. func main(): The main function is the entry point of the program.

  4. fmt.Println(): This function prints a line to the console.

Congratulations! You’ve written and run your first Go program.

What will you build next? #Golang