How to Install and Set Up Go (Golang) on Windows

How to Install and Set Up Go (Golang) on Windows

Go (or Golang) is a powerful, open-source programming language developed by Google. It is widely used for building scalable and high-performance applications. If you're a Windows user, this guide will walk you through the installation and setup of Go on your system.

Prerequisites

Before installing Go, ensure you have:

  • A Windows 10 or later operating system.

  • Administrator access to install software.

  • A stable internet connection.

Step 1: Download the Go Installer

  1. Open your browser and visit the official Go website: go.dev/dl

  2. Look for the latest Windows version of Go (e.g., go1.x.x.windows-amd64.msi).

  3. Click on the download link to save the .msi file.

Step 2: Install Go on Windows

  1. Locate the downloaded .msi file and double-click to run the installer.

  2. Click Next on the welcome screen.

  3. Accept the license agreement and click Next.

  4. Choose the installation destination (default is C:\Go), then click Next.

  5. Click Install and wait for the installation to complete.

  6. Click Finish to exit the installer.

Step 3: Set Up Environment Variables

To ensure Go works properly, you need to verify its environment variables:

  1. Open the Start Menu, search for Environment Variables, and open Edit the system environment variables.

  2. In the System Properties window, click Environment Variables.

  3. Under System Variables, locate Path and click Edit.

  4. Ensure C:\Go\bin is listed. If not, click New, enter C:\Go\bin, and click OK.

  5. Click OK on all windows to save changes.

Step 4: Verify Go Installation

To confirm Go is installed correctly:

  1. Open Command Prompt (cmd) or PowerShell.

  2. Type the following command and press Enter:

     go version
    
  3. You should see an output similar to:

     go version go1.x.x windows/amd64
    

    If you see this, Go is installed successfully!

Step 5: Set Up Go Workspace

  1. Open File Explorer and navigate to your user directory (C:\Users\YourUsername).

  2. Create a new folder named go (this will be your workspace).

  3. Inside the go folder, create three subfolders:

    • bin (for compiled binaries)

    • pkg (for compiled package objects)

    • src (for Go source code)

  4. Open Command Prompt and run:

     go env
    

    This displays your Go environment variables. Ensure GOPATH is set to C:\Users\YourUsername\go.

Step 6: Create and Run Your First Go Program

  1. Open a text editor (such as Notepad++ or VS Code) and create a new file named hello.go inside C:\Users\YourUsername\go\src.

  2. Add the following code:

     package main
     import "fmt"
     func main() {
         fmt.Println("Hello, Go!")
     }
    
  3. Open Command Prompt, navigate to the src directory:

     cd C:\Users\YourUsername\go\src
    
  4. Compile and run the Go program:

     go run hello.go
    

    You should see:

     Hello, Go!
    

Conclusion

You have successfully installed and set up Go on Windows! Now you can start exploring Go programming by creating projects and building applications. If you encounter any issues, refer to the official Go documentation: go.dev/doc.

Happy coding!