Skip to content

Golang

Cheatsheets

Tutorials/Courses

Official

Free/Teaser

Commercial/Paid

The Hello World

With your choice of command line tool, enter your home directory.

bash
cd

# Windows legacy versions (before 11)
cd %HOMEPATH%

Create a project folder for the trial.

bash
mkdir trial-golang
cd trial-golang

Initiate the project module

bash
go mod init example/trial-golang
bash
# Output
go: creating new go.mod: module example/trial-golang

Create a file names hello.go in the project folder. Paste the following codes into it, then save the file:

go
package main

import "fmt"

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

Run the code to view the output.

bash
go run .
bash
# Output
Hello, World!