How to run a Golang Program?

11 Dec, 2022, 1 min read

How to run a Golang Program?

Golang makes it easy to compile and run a go program using the command go run filename.go

Steps to run a Golang program

  1. Once you have installed Go, you can create a new file with a .go extension. If you want to install Go, you can follow the official docs here

  2. Create a new file called firstprogram.go (You can have any name here to represent your project)

  3. Add the following code to the file

    package main
    import "fmt"
    func main() {
    	fmt.Println("This is my first program in Go")
  4. Run the command go run firstprogram.go

  5. Output of the command

This is my first program in Go

Syntax to run the golang program

go run <filename>.go

Join our mailing list

We will reach out when exciting new posts are available. We won’t send you spam. Unsubscribe at any time.