Build Your First Go Program on Windows and Master the go build Command

This tutorial walks you through creating a simple Hello World program in Go on Windows, running it in Goland, and using the go build command to compile the source into an executable file with custom naming options.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
Build Your First Go Program on Windows and Master the go build Command

Introduction

Hello, I’m 星期八, a developer sharing a quick guide on writing and building your first Go program on Windows.

First Go Program

Every new language starts with a Hello World example. Open Goland, create a main.go file, and add the following code:

package main // package name, main indicates an executable program; only one main package per directory

import "fmt" // import package

func main() { // entry point
    fmt.Println("Hello world")
}

Save the file, then right‑click in the editor and choose Run to execute the program.

Using the go build Command

The program runs via run main.go, but Go is a statically compiled language, so you can produce a standalone executable.

Open a command prompt, navigate to the project directory, and run: go build This compiles main.go into an executable file (e.g., main.exe on Windows).

You can specify the output file name with the -o flag:

go build -o helloworld.exe

The resulting executable appears in the directory:

Conclusion

This article demonstrated how to write a basic Go program, run it in Goland, and compile it into a Windows executable using go build. Stay tuned for the next tutorial.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

GoProgramming tutorialHello Worldgo build
Python Crawling & Data Mining
Written by

Python Crawling & Data Mining

Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.