Write Hello World app in Go

Hey! If you love Go and building Go apps as much as I do, let's connect on Twitter or LinkedIn. I talk about this stuff all the time!

Want to learn how to build better Go applications faster and easier? You can.

Check out my course on the Go Standard Library. You can check it out now for free.


Hello Gophers!

Today, we’re going to walk through how to create and run a “Hello, world!” app in Go. This is a great first step for anyone who is new to the language or wants to get a quick taste of what Go can do.

First things first, let’s create a new file and call it main.go. In Go, all executable programs must have a main package, so we’ll start by declaring that at the top of our file:

package main

Next, we’ll import the fmt package, which contains functions for formatting and printing output:

import "fmt"

Now, let’s write our main function. This is the entry point of our program, and it’s where we’ll print our “Hello, world!” message:

func main() {
    fmt.Println("Hello, world!")
}

The Println function takes a string argument and prints it to the console with a newline character at the end. In this case, we’re simply passing the string “Hello, world!”.

Now that we’ve written our program, it’s time to compile and run it. To do this, we’ll use the Go command-line tool. Open your terminal and navigate to the directory where you saved the main.go file.

Then, type the following command to build and run the program:

go run main.go

You should see the message “Hello, world!” printed in your terminal.

And that’s it! You’ve just created and run your first Go program. Congratulations!

In this tutorial we:

  • Created a new file called main.go
  • Declared the main package at the top of the file: package main
  • Imported the fmt package: import “fmt”
  • Wrote the main function: func main() { fmt.Println(“Hello, world!") }
  • Compiled and ran the program with the command: go run main.go

And that’s it! Congrats, you’re a Go coder now.

Thanks for reading, and happy coding!


Questions or comments? Reach out to me


Learn how to leverage the Go Standard Library like a PRO.

I just created a new course, The Go Standard Library, check it out!