How to install golang in windows?
March 12, 2022Hi Friends 👋,
Welcome To aGuideHub! ❤️
Today, we are going to install and run golang in windows, here I’m not going to tell you what Go is and why we use it, I think you already know, and that’s why you are searching for installation steps of Go programming.
Table of contents
- Download and install the Go compiler.
- Setup environment variable
- Write and run sample code
Let’s start with the first step.
Step 1: Download and install Go compiler
Go to https://go.dev, press the download button and it will redirect you to the Download page, where you will see an option of OS ( operating system )
Now Double click on the downloaded file it will open something like the below image press Next three times and the Install button then it will install Go in your windows.
Golang has been installed successfully. Now we need to check if it has been set up correctly. We can check that from the command prompt or any other terminal. Here we will use CMD.
Enter the command below to check the installed GoLang version:
go version
Let’s move to the environment variables setup.
Setup environment variables
Now we need to check if GOPATH is set up properly.
To check that open Control Panel. Then go to System and Security and click on System.
A window will open as shown below.
Open Advanced System Settings from left sidebar and then click on Environment Variables.
Check if GOPATH is set. Here in the image above GOPATH is set to %USERPROFILE%\go.
You can set it to any folder you prefer.
To change GOPATH just click Edit and then either write the path or browse the folder.
Congratulations! You have installed go in your Windows successfully.
Write and run sample code
To check our installation working properly or not we are going to write a simple hello world program in golang.
I have just created a hellw-world folder with an index.go file where I have written Print hello world program.
// First Go program
package main
import "fmt"
// Main function
func main() {
fmt.Println("!... Hello World ...!")
}
And here is our output of the above code.
To run go code we have command
go run filename.go
Thanks for reading this article.