How to run a Golang Program?

How to run a Golang Program?

How to run a Golang program to get the output of the Go in command line

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