How do I write my first Go program and run it?

To write your first Go program, follow these steps:

  1. Install Go by visiting the official Go website at golang.org/dl and downloading the installer for your operating system.
  2. Set up a workspace. You can create a directory for your Go projects, for example: mkdir ~/go_projects.
  3. Create a new Go file. Use your favorite text editor to create a file named HelloWorld.go in your workspace.
  4. Write the following code in HelloWorld.go:
package main import "fmt" func main() { fmt.Println("Hello, World!") }

To run your program, open your terminal or command prompt, navigate to your workspace, and execute the following command:

go run HelloWorld.go

You should see the output:

Hello, World!

Go programming first Go program Golang hello world in Go Go tutorial