Go, Software Development

Golang go and exe Files

This post shows how to run your Golang go script and convert it as an exe file in Windows.

Install Golang for Windows

I am running a 64-bit Windows 10 box.

First, Download Golang Installer (exe file)

Proceed to the download page and download the appropriate version for your system. For this post, we will use a Golang installer. Alternatively, we can use the Golang playground available online if we cannot install Golang on our system.

 

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.

Then, Verify Installation

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

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

Golang “Hello World” from .go and .exe

Here are short Golang codes that display “Hello World” on the command-line prompt from a go and exe files.

1. Run Golang Codes as a go file

The filename for our Go codes is helloworld.go

To run a Golang go file, use the following command.

2. Run Golang Codes as an exe file

Before running our Go program as a .exe, we need to convert it first to exe explicitly. First, you need to point the environment variable GOBIN to your .go file’s path.

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

The command will generate a helloworld.exe file in the current directory.

Golang go exe files

Run it now

Golang go exe files

We have successfully compiled and run our Golang codes as go and exe files.

Loading

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like