How to Print Hello World in Go Language

Hey guys in this post, we will see how to print Hello world in Go programming language with detailed explanation.

1. Create a directory

mkdir go-workspace

2. Move inside the directory

cd go-workspace

3. Create an empty file

code HelloWorld.go

Keyword code represents Visual studio code, it will open the file inside the Visual studio code.

Note: I will be using Visual studio code for writing code but you can use any other text editors or IDEs for writing code.

4. Write the Hello world Program

package main

import "fmt"

func main() {
	fmt.Println("Hello World")
  • The main package must have package name main and declare a function main that takes no arguments and returns no value.
  • Program execution begins by initializing the main package and then invoking the function main
  • When that function invocation returns, the program exits. It does not wait for other (non-main) goroutines to complete.
  • Println() method is used to print the message to the console.

5. Run the Program

To run the program, open the command prompt and execute the following command

PS C:\workspace\go lang workspace> go run .\HelloWorld.go
Hello World

Bushan Sirgur

Hey guys, I am Bushan Sirgur from Banglore, India. Currently, I am working as an Associate project in an IT company.

Leave a Reply