0

Go – helloworld .go and .exe

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 special configuration or settings during the installation or even thereafter. 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 very simple Go codes that displays “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 an .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