Run Go Program

Once you have installed Golang on your computer, you may be wondering on how to run your first hello world program.

To run a go program, create a file with an extension .go and write your golang code in that file. For example, we will create a file named helloworld.go and write the following code in it.


package main  

import "fmt"  

func main() {  
   fmt.Println("Hello World")  

Now open command prompt and navigate to the location of helloworld.go file. Run the following command.

go run helloworld.go

If the environment setup is correct, the program should run without any errors and echo back “Hello World” to the command prompt or terminal.

run go lang program in command prompt

The syntax to run the the go file is:

go run filename

where filename is the name of the file with go code. The extension is also required for the file name.


In this Golang Tutorial, we learned how to write a Golang Program and run it in your computer.