Go, Software Development

Go – helloworld .go and .exe

Golang Write Text File

This post demonstrates how to run your .go script and convert it as a .exe file in Windows.

Install Go for Windows

I am running a 64-bit Windows 10 box with the following OS details.

Download Go

Go to https://golang.org/ and click the “Download Go” link

Then choose Go for Windows by clicking the “Microsoft Windows” download link.

Once the installer download completes, install it to your local machine. Just click your way through the installation process.

Verify Installation

There is no particular configuration or settings during the installation or even after that. Open your Windows command-line prompt to verify Go’s version.

Why is my prompt different? Please see DOS – Change your command line prompt.

“Hello World” from .go and .exe

Here is a straightforward Go codes that display “Hello World” on the command-line prompt.

Run as .go

The filename for our Go codes is helloworld.go

Run it now

To execute a .go file, use

Run as .exe

Before we can run our Go program as a .exe, we need to explicitly convert it first to .exe.

Convert to .exe

First, you need to point the environment variable GOBIN to the path where you  .go file is.

Then, in the same directory, run the following command:

This will generate a helloworld.exe file.

Run it now

Got comments, or suggestions? Please visit our Facebook page!

You Might Also Like