Setup Go in Windows

So you heard about Go awesomeness right? Awesome! Go works pretty well in Windows too! Let's start off by installing Go toolchain in your own Windows. I managed to have access to a Windows7 through a nearby cyber cafe but having a hard time finding Windows10 in my neighborhood across 2 town (Yikes!). Nevertheless, Windows10 should not be too different from it.

Wait, What?!

I use Ubuntu / Debian and Mac in my everyday work so hunting a Windows10 is really hard in my neighborhood. My friends are using Mac as well.

This page is dedicated to a young talent who is picking up Go on his journey at the remarkable age of 9. You inspired me. Special thanks to:

  • Author: Chew, Kean Ho
  • Editor: David Skinner
  • Windows Machine: Orange ESport Cyber Cafe
NOTE
This guide is equipped with A LOT of pictures. You're advisable to use Wifi to access this site.

Our Objectives

Our highest priority is to install Go and its necessary software here. Go has a dependency which is git. Hence, there are a minimum of 2 installations. As for a software to edit our code, we need to get one, which is Notepad++. Therefore, our objectives are:

  1. Install Git, the Go dependency
  2. Install Go
  3. Install Notepad++

What Do We Learn

  1. How to setup Git and test it
  2. How to setup Go and test it
  3. How to setup Notepad++, configure, and then test it
  4. How to install software in Windows (Step by Step)
  5. How to read documentation and learn things on the fly

Let's begin!

Step 1 - Checking Your System

Before we install any software, we have to learn our system first. There are 3 very important information we must know:

  • What is the "bit" version of your Windows operating system (32-bit or 64-bit)
  • What is the "type" of our cpu (intel? amd? arm? powerpc? etc.)
  • How much space do we have to install all the softwares

These information are important since today's software are packed in different "packages" to suit the cpu.

#1 - Bring up dxdiag program

On Windows, we use a program called dxdiag which can report detailed explanation about our computer. To do that:

  1. Press START
  2. In the search bar or (type RUN ) and type dxdiag
  3. Run the dxdiag program.
Step 1-1 - Opening dxdiag
Step 1-1 - Open dxdiag Program (zoomed)

#2 - Select Yes if Prompted

If you get a prompting that a driver checking, grant it a yes. Don't worry, it only reports the computer hardware.

Step 1-2 - Dxdiag Driver Prompt

#3 - Analyze the Operating System Bit Type

Once the DirectX diagnostic tool reported its findings, check the "Windows X-bit version". You can also learn a lot about your computer here too!

If it mentions 64-bit, it 64-bit. Otherwise, it's 32-bit Windows.
If it mentions Intel/AMD processor, it means amd64 for 64 bit, i386 for 32 bit.

Note this information down, we'll need it for the installation. In software world, this is how we download the correct software package.

Step 1-3 - Study the CPU

#4 - Find out the Disk Space

Now is we need to check we have enough space to install the tool-chains.

  1. Go to MY COMPUTER and check the c: drive size. We need:
  • minimum 500 MB (0.5GB) for all the installations in this components (Go, Git, Notepad++, and some space for you write your code)
NOTE:
If you run short of free space, you might want to uninstall some software/game or delete some old files in your computer. 
Step 1-4 - Study Free Space

Step 2 - Install Dependencies

Now that we understand our system, it's time to install the dependency first: Git. Go uses Git to get the source codes from the Internet. When we install a software, we must always find out what it depends on before installing it. Otherwise, the software might crash or worst, may not work properly in the future. Let's get started.

#1 - Download Git from https://git-scm.com/download/win

Head over to the https://git-scm.com/download/win to download the git software. The Download automatically works once you visit the website.

NOTE: in case the automatic download doesn't work, select the correct bit version to download manually. Don't go for thumb-drive edition. We don't need that.

The bit version is what we learned from Step #1. So if the dxdiag was reporting 64-bit, download the 64-bit version. Otherwise, the 32-bit.
Step 2-1 - Download Git from Website

#2 - Install Git

Once the download is completed, you can proceed to install it. Let's double click the installer.

Step 2-2 - Run Git Installer

#3 - Grant Permission to Run the Installer

Select Run when prompted permission. If you got permission denied. You might need to talk to your admin (or your parent) to unlock it for you.

Step 2-3 - Grant Permission to Git Installer

#4 - Read then Accept The License

Every proper software has its licenses. This is to protect itself from certain use, say like someone sell it illegally. Hence, as a good software developer, it is a good habit to read through before you proceed to NEXT.

Step 2-4 - Read and Accept Git License

#5 - Configure the Git Installation

Most of the default settings are good. Until one thing that you need to watch out: the unchecked Check daily for Git for Windows updates option. We want that. Hence,

  1. Remember to select Check daily for Git for Windows updates.
  2. Select NEXT.
Step 2-5 - Configure Git Installer

#6 - Installation Path

Here, the default installation path is Git. Let's not change it. Proceed by pressing NEXT.

Step 2-6 - Set Git Installation Path

#7 - Select Commit Editor

Now the installer wants us to select with editor to choose when we use git commit. It like a writing a small contract stating

Hey, I'm commiting my codes into this software repository. These codes changes are from me.

I recommend using Notepad++ since we're going to install that editor later. Remember to change it. Once done, select NEXT.

Step 2-7 - Selecting Commit Editor

#8 - Selecting Git Command Prompt

Now the install asks us whether to choose which type of command prompt to use. Go uses the default Windows Command Prompt (cmd). Hence,

  1. Let's change it to Use Git from the Windows Command Prompt
  2. Proceed to NEXT
Step 2-8 - Selecting Command Prompt for Git

#9 - Setting HTTPS library

Now the installer presents us a set of complicated settings. This is the security over Internet configuration. In Windows, we have an option to use Windows Secure Channel library or the OpenSSL library; To decide for it is kind of complicated. If in doubt, stick to default, which is:

  1. Select Use the OpenSSL Library
  2. Select NEXT
Step 2-9 - Selecting HTTPS Library

#10 - Select Commit Message Ending

Now Git wants us to decide the ending format for commit message. Ending format is a symbol (\r\n, \n, \r) to indicate a new line is created. It is also known as "End of Line".

Since almost all Git users and developers alway use Unix system for automation and deployment, it is best to choose the ending with Unix-Style. Hence,

  1. Select Checkout Windows-style, commit Unix-style line ending
  2. Select NEXT
Step 2-10 - Selecting Commit Message Ending

#11 - Enable Git Features

Now Git is asking us to enable some features that Windows doesn't have. We can leave the default on and finally! proceed with Install.

Step 2-11 - Enable Git Features

#12 - Breath In, Breath Out!

Installation has begun. Let's go grab some cookie and some exercise while waiting for it to complete.

Step 2-12 - Breath In, Breath Out! It's Installing

#13 - Launch Git Bash

Now that the installation is completed, It's time to test it out.

  1. Let's check Launch Git Bash
  2. Then select FINISH
Step 2-13 - Launching Git Bash

#14 - Test Git in Git Bash

Well, we never know whether it is working or otherwise. Let's test it first. Once you press finish, a terminal immediately popup out.

  1. Type Git to see if the program is running properly.
  2. Compare it with the screenshot. If it's showing as the screenshot did, it means it's working for now.
  3. Let's close it by typing exit on the next command.
Step 2-14 - Test Git in Git Bash
Step 2-14 - Test Git in Git Bash (Zoomed)

#15 - Launch Windows Command Prompt

Remember that we need git to work in Windows Command Prompt (cmd) as well? Now we're about to test it. Let's launch a CMD prompt.

  1. Select START
  2. Search / Run
  3. Type cmd. Then launch it.
Step 2-15 - Launch Windows Command Prompt (zoomed)

#16 - Test Git in Windows Command Prompt

Repeat the same process again in this terminal.

  1. Type git
  2. You must see the same thing. If you do, congrats! You just installed git in your Windows. Otherwise, you need to reinstall it again.
  3. Type exit to close the cmd.
Step 2-16 - Test Git in Windows Command Prompt
Step 2-16 - Test Git in Windows Command Prompt (Zoomed)

Step 3 - Install Go

Now that we had completed our Git installation, it's time to install the main course: Go! Let's begin its installation and try some stuff out!

#1 Download from https://golang.org/dl/

Head over to https://golang.org/dl/. Select the correct msi package based on what we learned from the computer (Step #1). Ensure you choose the stable version, and the latest too! Remember:

  • Intel/AMD processor - 32-bit is 386
  • Intel/AMD processor - 64-bit is amd64

#2 Install the Go MSI

Now that we have the package, let's install it! Since you know how to install Git already, give Go a try on your own. It's the same process to install Git.

Step 3-2 - Install GoLang MSI
Step 3-2 - Grant Permission to GoLang Installer
Step 3-2 - Running GoLang Installer
Step 3-2 - Installing GoLang

#3 - Some Minor Setup

Now that we have Go installed, there are some minor setup we need to do before proceeding to use it. Let's start by bringing out our windows command prompt (cmd).

  1. Launch a Windows Command Prompt (Press START > search/run > cmd). In the command, type go env. It should gives you a list of settings.
  2. We want to take note of GOPATH, it points to where the project location is.
  3. Now, open up an window explorer, select c: drive.
  4. Slowly select the folder Users\<the name> until it shows the correct location as the GOPATH. In the screenshot, the user is called orange so it shows orange. You'll immediately notice that we don't have a go folder. That's where want to create it.
  5. Right click inside the window.
  6. Select New
  7. Select Folder
  8. Name it "go" and press ENTER. (note: go is very sensitive, so make sure it is the same as GOPATH. Typing Go or gO won't work.). Enter the go folder you had created. You can select the address bar to check the address is the same as GOPATH.
  9. We need to create 3 folders inside here. Hence, right click again inside the window, select new > folder. Name the folders:
    • bin
    • src
    • pkg
Step 3-3 - Setup GoLang Folder 1-7
Step 3-3 - Setup GoLang Folder 8
Step 3-3 - Setup GoLang Folder 9-11
Step 3-3 - Setup GoLang Folder Final

#4 - Test It

Now that our project folder is ready, we may test it. Remember, all your go work is inside this folder, as stated in GOPATH. Let's begin our testing.

  1. let's go into our folder by typing cd %GOPATH%
  2. We'll get an example project. Type go get github.com/golang/example/hello. A proper response is a no-response.
  3. To check it is working properly, let's go in the src folder. You'll notice a folder github.com is created. If you go in further, you'll see the source code. That means go is working fine now.
  4. Just to double confirm, let's try to run it. Type %GOPATH%/bin/hello in the terminal. You'll get a response. This means the hello is compiled successfully. Congrats so far! go is good now.
Step 3-4 - Testing Go 1-2
Step 3-4 - Testing Go 3
Step 3-4 - Testing Go 4

#5 - Another Minor Setup

Now that we know our go is working fine, there is another setting we need to do: GOBIN. If you notice, it's missing now. Let's setup and test it out.

  1. Click START > Control Panel > System > Advanced System Settings
  2. Select Environment Variables.
  3. Select New for user variables.
  4. Fill in:
    1. name = GOBIN
    2. value = Same as GOPATH (shown in orange) but add a \bin behind.
      • NOTE: Windows 10 is slightly different from the picture, but the method is the same.
  5. Press OK > OK > OK to accept the new creation.
  6. Open a new command prompt (START > search / run > cmd)
  7. Type go env.
  8. Notice the GOBIN is now having value.
  9. let's do %GOBIN%/hello again. You should get the same test result. This means the GOBIN is configured properly! Hooray. Go setup is finally completed!
Step 3-5 - Final Tweaking for GOBIN 1-4
Step 3-5 - Final Tweaking for GOBIN 7-9

Step 4 - Setup Notepad++

Now that we have the go up and running, we need an editor to write our code. I recommend you to use Notepad++ (the best so far) and it's free. Let's setup now.

We'll first download the Notepad++ from its official website. Proceed to https://notepad-plus-plus.org/download and download the latest version. Notepad++ works on Intel cpu. You just need to select the correct bit version.

Step 4-1 - Download Notepad++

#2 - Install it

Now we have the installer, we can proceed to double click and install it. Just like Go, give it a try on your own. At the end of the installation. Notepad++ will launch itself to perform its self-testing. If you see the contents CHANGELOG, hooray! You installed it successfully.

Step 4-2 - Launch Notepad++ Installer
Step 4-2 - Grant Permit to Install Notepad++
Step 4-2 - Setup the Installer
Step 4-2 - Begin Installation
Step 4-2 - Set Installation Path
Step 2-4 - Completed Installation

#3 - Configure Notepad++ Preferences

Now that we have a proper editor for coding, there is one small thing we need to set before going into coding. Since most Go developers are using Linux or Mac, it's better to set the editor to those modes. Don't worry, you can always adjust accordingly.

Select Settings > Preferences

Step 4-3 - Entering Preferences

Select New Document > Set Unix OR Mac > Close to save.

Step 4-3 - Set Ending for Notepad++

#4 - Set Notepad++ to open .go files

Now that everything is ready, let's head back to the go source code. Remember the %GOPATH%/src has github.com folder? Let's check it out.

  1. Let's enter the folder: c:/Users/<username>/go/src/github.com/golang/sample/hello.
  2. If the hello.go is a blank white file, it means Notepad++ is not configured yet. Right click the file.
  3. Select Open.
NOTE:
If hello.go is recognized by Notepad++ (the file has a chameleon in it), you can skip all the following steps. Notepad++ is well configured and you're ready to code!

These steps are here just in case otherwise.
Step 4-4 - Opening .go file with Notepad++


  1. Check the Always use the selected program to open this kind of file.
  2. Locate Notepad++, it should be inside c: > Program Files OR c: > Program Files (x86)
  3. Gocha! Now enter Notepad++ folder.
Step 4-4 - Finding Notepad++ program
  1. Select the notepad++
  2. Select Open
  3. If it needs for OK confirmation, press OK.
Step 4-4 Completing Default Program Action for Notepad++

Once you see the Notepad++ opens up the hello.go file, you're ready now for creating go application!

Step 4-4 - Notepad++ opened Go File

Did You Know?

There are some Go packages that can help you filter and correct your code as you save them? Check out:

There are other ways to install Go:

Conclusion

Now that you completed setting up your Git, Go and Notepad++ in your Windows, you can now proceed to create your own go program. Nevertheless, happy coding!