Skip to main content

Command Palette

Search for a command to run...

Installing Go on Windows 11 and Running Your First "Hello World" Program

Published
3 min read
Installing Go on Windows 11 and Running Your First "Hello World" Program
N

👋 Welcome to my Hashnode profile! I'm a passionate technologist with expertise in AWS, DevOps, Kubernetes, Terraform, Datree, and various cloud technologies. Here's a glimpse into what I bring to the table: 🌟 Cloud Aficionado: I thrive in the world of cloud technologies, particularly AWS. From architecting scalable infrastructure to optimizing cost efficiency, I love diving deep into the AWS ecosystem and crafting robust solutions. 🚀 DevOps Champion: As a DevOps enthusiast, I embrace the culture of collaboration and continuous improvement. I specialize in streamlining development workflows, implementing CI/CD pipelines, and automating infrastructure deployment using modern tools like Kubernetes. ⛵ Kubernetes Navigator: Navigating the seas of containerization is my forte. With a solid grasp on Kubernetes, I orchestrate containerized applications, manage deployments, and ensure seamless scalability while maximizing resource utilization. 🏗️ Terraform Magician: Building infrastructure as code is where I excel. With Terraform, I conjure up infrastructure blueprints, define infrastructure-as-code, and provision resources across multiple cloud platforms, ensuring consistent and reproducible deployments. 🌳 Datree Guardian: In my quest for secure and compliant code, I leverage Datree to enforce best practices and prevent misconfigurations. I'm passionate about maintaining code quality, security, and reliability in every project I undertake. 🌐 Cloud Explorer: The ever-evolving cloud landscape fascinates me, and I'm constantly exploring new technologies and trends. From serverless architectures to big data analytics, I'm eager to stay ahead of the curve and help you harness the full potential of the cloud. Whether you need assistance in designing scalable architectures, optimizing your infrastructure, or enhancing your DevOps practices, I'm here to collaborate and share my knowledge. Let's embark on a journey together, where we leverage cutting-edge technologies to build robust and efficient solutions in the cloud! 🚀💻

Introduction

In this blog, we'll guide you through the process of installing Golang on Windows 11 and writing your first Go program, "Hello World." Follow these steps to get started with Golang on your Windows machine.

Step 1: Downloading and Installing Go

  1. Visit the Official Go Website:

  2. Download the Installer:

    • Click on the Windows download link to get the installer (e.g., go1.22.5.windows-amd64.msi).
  3. Run the Installer:

    • Double-click the downloaded .msi file to run the installer.

    • Follow the prompts to complete the installation. The installer will automatically add Go to your system PATH.

Step 2: Verifying the Installation

  1. Open Command Prompt:

    • Press Win + R, type cmd, and hit Enter.
  2. Check the Go Version:

    • Type go version and press Enter.

    • You should see the installed Go version (e.g., go version go1.22.5 windows/amd64).

Step 3: Setting Up Your Go Workspace

  1. Create a Workspace Directory:

    • Open Command Prompt and navigate to your preferred location.

    • Create a new directory for your Go projects:

        mkdir GoProjects
        cd GoProjects
      
  2. Set the GOPATH Environment Variable:

    • The GOPATH is the root directory of your workspace.

    • You can set it in your environment variables. Right-click on This PC, select Properties, then Advanced system settings, and finally Environment Variables.

    • Add a new user variable named GOPATH and set its value to the path of your workspace directory (e.g., C:\Users\YourUsername\GoProjects).

Step 4: Writing Your First Go Program

  1. Create a New Directory for Your Program:

    • Inside your workspace directory (GoProjects), create a new directory for your "Hello World" program:

        mkdir hello
        cd hello
      
  2. Create the Go Source File:

    • Open your favorite text editor or IDE (such as Visual Studio Code).

    • Create a new file named hello.go and add the following code:

        package main
      
        import "fmt"
      
        func main() {
            fmt.Println("Hello, World!")
        }
      

Step 5: Running Your Go Program

  1. Navigate to Your Program's Directory:

    • Open Command Prompt and navigate to the directory containing hello.go:

        cd C:\Users\YourUsername\GoProjects\hello
      
  2. Build and Run the Program:

    • To compile and run your program, use the following command:

        go run hello.go
      
    • You should see the output:

        Hello, World!
      

Explanation of the "Hello World" Program

  • package main: Defines the package name. The main package is a special package in Go that defines a standalone executable program.

  • import "fmt": Imports the fmt package, which provides formatting functions for input and output.

  • func main(): The main function is the entry point of the program. When you run the program, the main function is executed.

  • fmt.Println("Hello, World!"): Prints the string "Hello, World!" to the console. The Println function adds a newline character at the end.

Conclusion

Congratulations! You've successfully installed Go on Windows 11 and run your first Go program. In this blog, we've covered the installation steps, setting up your workspace, and writing and running a simple "Hello World" program.

Stay tuned for more tutorials and tips on mastering Golang! Happy coding!

More from this blog

NavyaDevops

78 posts

DevOps Engineer with advanced skills in cloud technologies. Proven track record in optimizing development and deployment processes. Dedicated to innovation and scalability in software development.