How to Run a Go Program with a Plain Text File

Go (golang) programming language

In this article, we show how to run a first Go program with a plain text file.

You don't need an advanced software program such as Visual Studio Code to write and run a Go program. You can write a Go program with simply a text editor, which in Windows can be Notepad or in Linux can be Nano.

The thing you need to know is where th Go software is installed on your computer. If you are on a Windows system, by default, it is installed in, C:\Go

What you need to do is open the plain text editor and write the Go program in this file and save the file in the src folder of the Go folder. You will save all created Go files in the folder, C:\Go\src

You can then run the Go program through command prompt.

We will first create a Go program.

The most basic Go program that we can create is probably the "Hello World" program, which is what we will do in this case.

The source code to do this is shown below.

Now make sure that you save this file within the src folder of Go. Make sure you save the file with a .go extension, so that it's a Go file. You can call this file anything, such as main.go, firstprogram.go, helloworld.go, etc.

I call my file, firstprogram.go

Next, open up the command line or command prompt.

This is how we can execute our Go program.

When you are in this command line, make sure that you navigate into the src folder of Go, where you saved your file.

Once you've navigated into this folder, then run the following line.

Once you run this, you should see the output of your program appear, which in this case is, Hello World, unless you modified this text.

This is how it will appear using Command Prompt on a Windows PC.

Running a go program with a plain text file

So you now know how to create and run a Go program using a plain text editor and a plain text file.

Using a plain text editor is very simple and straightforward. It doesn't offer advanced capabilities such as error detection and indentation that a more advanced software editor offers, but if you're writing a simple program or you are just more comfortable with using a plain text editor, it offers a good and effective way to run a Go program.

So this is how to run a Go program with a plain text file.

Related Resources

How to Check the Version of Go Installed on a Windows PC

HTML Comment Box is loading comments...