Skip to content

Your First Program

Create a folder and initialize a module — this is the Go equivalent of npm init or cargo init:

Terminal window
mkdir hello && cd hello
go mod init example.com/hello

This creates a go.mod file that names your module and tracks its dependencies. Now create main.go:

package main
import "fmt"
func main() {
fmt.Println("Hello, nasigolang!")
}

Every executable Go program needs a package main and a func main() — that’s the entry point. Run it directly with:

Terminal window
go run main.go

go run compiles and executes in one step, which is great for development. To ship something, compile a standalone binary:

Terminal window
go build -o hello .
./hello

The result is a statically linked binary with no runtime dependencies — you can copy it to another machine (same OS/arch) and it just runs. This is one of the reasons Go is popular for CLI tools and infrastructure software.

  • package main declares this file belongs to the main package, the one Go treats as an entry point.
  • import "fmt" pulls in the standard library’s formatted I/O package.
  • func main() is called automatically when the binary starts. No arguments, no return value.