Here we are going to write our first Program in Go languages i.e., “Hello world”. We can also say that our first program was in Golang.
You can write a Go program in any text editor or IDE like VS Code. Just create a file with the .go extension, here we will create helloWorld.go and write the code for printing hello world in the Go language.
helloWorld.go
package main
import "fmt"
func main() {
fmt.Println("Hello world !!!!!")
}
package main and function main is compulsory for executing any go program. After that we are using the ‘fmt’ package for printing ‘Hello world’. ‘fmt’ package provides the option for taking input and printing. We can use ‘print
‘, ‘println
‘, ‘printf
‘ for printing anything in go.
Executing Hello World in Go
If you are using VS Code then you can execute/run this program directly with the help of the code runner extension
else you can run this program in the terminal – open the terminal in the current folder and run the following command and you will see the desired output
go run helloWorld.go
For running the go programs on a local machine go compiler should be installed on your system. If Go is not installed in your System, you can check the following video and follow the steps for installing Golang.
You can check more tutorials on Golang here
5 thoughts on “Hello World in Go”