How to run a Golang Program?
How to run a Golang program to get the output of the Go in command line- Sriram Thiagarajan
- December 11, 2022
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
-
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
-
Create a new file called
firstprogram.go
(You can have any name here to represent your project) -
Add the following code to the file
package main import "fmt" func main() { fmt.Println("This is my first program in Go") }
-
Run the command
go run firstprogram.go
-
Output of the command
This is my first program in Go
Syntax to run the golang program
go run <filename>.go