To write and run a basic "Hello, World!" program in Go, you can follow these steps:
Open a text editor and create a new file with a .go
extension, such as hello.go
.
In the hello.go
file, write the following code:
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
Save the file.
Open your terminal or command prompt and navigate to the directory where you saved the hello.go
file.
Run the program using the go run
command followed by the name of the Go file:
go run hello.go
Hello, World!
Congratulations! You have successfully written and executed a basic "Hello, World!" program in Go.