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:
- Install
Git
, theGo
dependency - Install
Go
- Install
Notepad++
What Do We Learn
- How to setup
Git
and test it - How to setup
Go
and test it - How to setup
Notepad++
, configure, and then test it - How to install software in Windows (Step by Step)
- 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:
- Press
START
- In the search bar or (type
RUN
) and typedxdiag
- Run the
dxdiag
program.
#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.
#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.
#4 - Find out the Disk Space
Now is we need to check we have enough space to install the tool-chains.
- Go to
MY COMPUTER
and check thec:
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 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.
#2 - Install Git
Once the download is completed, you can proceed to install it. Let's double click the 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.
#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
.
#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,
- Remember to select
Check daily for Git for Windows updates
. - Select
NEXT
.
#6 - Installation Path
Here, the default installation path is Git
. Let's not change it. Proceed by pressing NEXT
.
#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
.
#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,
- Let's change it to
Use Git from the Windows Command Prompt
- Proceed to
NEXT
#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:
- Select
Use the OpenSSL Library
- Select
NEXT
#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,
- Select
Checkout Windows-style, commit Unix-style line ending
- Select
NEXT
#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
.
#12 - Breath In, Breath Out!
Installation has begun. Let's go grab some cookie and some exercise while waiting for it to complete.
#13 - Launch Git Bash
Now that the installation is completed, It's time to test it out.
- Let's check
Launch Git Bash
- Then select
FINISH
#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.
- Type
Git
to see if the program is running properly. - Compare it with the screenshot. If it's showing as the screenshot did, it means it's working for now.
- Let's close it by typing
exit
on the next command.
#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.
- Select
START
Search
/Run
- Type
cmd
. Then launch it.
#16 - Test Git in Windows Command Prompt
Repeat the same process again in this terminal.
- Type
git
- You must see the same thing. If you do, congrats! You just installed git in your Windows. Otherwise, you need to reinstall it again.
- Type
exit
to close thecmd
.
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
.
#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
).
- Launch a Windows Command Prompt (Press
START
>search
/run
>cmd
). In the command, typego env
. It should gives you a list of settings. - We want to take note of
GOPATH
, it points to where the project location is. - Now, open up an window explorer, select
c:
drive. - Slowly select the folder
Users\<the name>
until it shows the correct location as theGOPATH
. In the screenshot, the user is calledorange
so it showsorange
. You'll immediately notice that we don't have a go folder. That's where want to create it. - Right click inside the window.
- Select
New
- Select
Folder
- Name it "
go
" and pressENTER
. (note:go
is very sensitive, so make sure it is the same asGOPATH
. TypingGo
orgO
won't work.). Enter thego
folder you had created. You can select the address bar to check the address is the same asGOPATH
. - We need to create 3 folders inside here. Hence, right click again inside the window, select
new
>folder
. Name the folders:bin
src
pkg
#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.
- let's go into our folder by typing
cd %GOPATH%
- We'll get an example project. Type
go get github.com/golang/example/hello
. A proper response is a no-response. - To check it is working properly, let's go in the
src
folder. You'll notice a foldergithub.com
is created. If you go in further, you'll see the source code. That means go is working fine now. - Just to double confirm, let's try to run it. Type
%GOPATH%/bin/hello
in the terminal. You'll get a response. This means thehello
is compiled successfully. Congrats so far!go
is good now.
#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.
- Click
START
>Control Panel
>System
>Advanced System Settings
- Select
Environment Variables
. - Select
New
for user variables. - Fill in:
- name =
GOBIN
- 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.
- name =
- Press
OK
>OK
>OK
to accept the new creation. - Open a new command prompt (
START
>search
/run
>cmd
) - Type
go env
. - Notice the
GOBIN
is now having value. - let's do
%GOBIN%/hello
again. You should get the same test result. This means theGOBIN
is configured properly! Hooray.Go
setup is finally completed!
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.
#1 - Download from https://notepad-plus-plus.org/download
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.
#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.
#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
Select New Document
> Set Unix OR Mac
> Close
to save.
#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.
- Let's enter the folder:
c:/Users/<username>/go/src/github.com/golang/sample/hello
. - If the
hello.go
is a blank white file, it meansNotepad++
is not configured yet. Right click the file. - 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.
- Check the
Always use the selected program to open this kind of file
. - Locate Notepad++, it should be inside
c:
>Program Files
ORc:
>Program Files (x86)
- Gocha! Now enter
Notepad++
folder.
- Select the
notepad++
- Select
Open
- If it needs for
OK
confirmation, pressOK
.
Once you see the Notepad++
opens up the hello.go file, you're ready now for creating go application!
Did You Know?
There are some Go
packages that can help you filter and correct your code as you save them? Check out:
- Golangci-Lint - https://github.com/golangci/golangci-lint
- Gonpp for Notepad++ - https://github.com/tike/GOnpp
There are other ways to install Go:
- Chocolatey.org - https://chocolatey.org/packages/golang
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!