codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
🐹

Go (Golang)

3 / 72 topics
1Introduction to Go (Golang)2Installation and Setup3Hello World Program4Variables and Constants5Data Types6Operators7Control Structures (if, else, switch)8Functions9Defer Statement10Panic and Recover
Tutorials/Go (Golang)/Hello World Program
🐹Go (Golang)

Hello World Program

Updated 2026-04-20
4 min read

Introduction

Welcome to the "Hello World" program tutorial in Go (Golang)! This foundational lesson will walk you through creating your first Go program. The "Hello World" program is a traditional starting point for learning any new programming language, as it provides an opportunity to understand basic syntax and structure.

What You Will Learn

By completing this tutorial, you will learn:

  • How to set up your Go development environment.
  • Basic Go syntax and structure.
  • How to compile and run a simple Go program.
  • Best practices for writing clean and efficient code.

Prerequisites

Before diving into the "Hello World" program, ensure that you have the following prerequisites:

  • Go Installed: Download and install the latest version of Go from the official website: golang.org/dl.
  • Text Editor or IDE: Use a code editor like Visual Studio Code, Sublime Text, or an Integrated Development Environment (IDE) such as GoLand.
  • Basic Understanding of Programming Concepts: Familiarity with basic programming concepts like variables, functions, and control structures will be beneficial.

Setting Up Your Go Environment

  1. Install Go:

    • Download the appropriate installer for your operating system from golang.org/dl.
    • Follow the installation instructions specific to your OS.
    • Verify the installation by running go version in your terminal or command prompt.
  2. Set Up Your Workspace:

    • Go uses a workspace to organize your code. By default, this is located at $GOPATH/src.

    • You can create a new directory for your projects and set it as your workspace.

    • For example, on Unix-like systems, you might set up your workspace like this:

      mkdir ~/go_projects
      cd ~/go_projects
      
  3. Configure Environment Variables:

    • Ensure that the GOPATH environment variable is set to your workspace directory.
    • Add $GOPATH/bin to your system's PATH to access Go binaries.

Writing Your First "Hello World" Program

Now, let's create a simple "Hello World" program in Go. Follow these steps:

  1. Create a New File:

    • Open your text editor or IDE.
    • Create a new file named hello.go.
  2. Write the Code:

    • Enter the following code into your hello.go file:

      package main
      
      import "fmt"
      
      func main() {
          fmt.Println("Hello, World!")
      }
      
  3. Save the File:

    • Save the file in your workspace directory.

Code Explanation

  • Package Declaration: Every Go program starts with a package declaration. For executable programs, this should be main.

    package main
    
  • Import Statement: The import statement is used to include packages that provide functionality to your program. Here, we import the fmt package, which provides functions for formatted I/O.

    import "fmt"
    
  • Main Function: The main function serves as the entry point of a Go executable program. When you run your program, execution begins here.

    func main() {
        fmt.Println("Hello, World!")
    }
    
  • Println Function: The fmt.Println function prints its arguments to the standard output, followed by a newline character.

Compiling and Running Your Program

  1. Open Terminal or Command Prompt:

    • Navigate to your workspace directory where you saved hello.go.
  2. Compile the Program:

    • Use the Go compiler to compile your program:

      go build hello.go
      
    • This command generates an executable file named hello (or hello.exe on Windows).

  3. Run the Executable:

    • Execute the compiled program by running:

      ./hello  # On Unix-like systems
      hello    # On Windows
      
    • You should see the output:

      Hello, World!
      

Best Practices

  • Use Meaningful Variable and Function Names: Choose descriptive names to make your code more readable.

  • Keep Functions Short and Focused: Each function should perform a single responsibility.

  • Comment Your Code: Use comments to explain complex logic or important decisions in your code.

  • Follow Go's Conventions: Adhere to the style guidelines outlined in the Go Style Guide.

Conclusion

Congratulations! You have successfully created and run your first "Hello World" program in Go. This simple exercise has introduced you to essential concepts such as package declarations, import statements, functions, and basic I/O operations.

As you progress in learning Go, continue to practice writing small programs and gradually tackle more complex tasks. The Go language's simplicity and efficiency make it an excellent choice for both beginners and experienced developers alike.

Feel free to explore additional resources, participate in the Go community, and experiment with different features of the language to deepen your understanding. Happy coding!


PreviousInstallation and SetupNext Variables and Constants

Recommended Gear

Installation and SetupVariables and Constants