We do not need an installer to install Golang in Windows. We only need a zip version of its distribution and some environment variables to avoid system-wide impact like installers do. It sounds easy, but doing so requires some knowledge of DOS commands; therefore, it is not for newbies or non-technical people.
What Do We Need?
The essential requirement for this post includes the following.
- Windows 10 or 11 (if you already have it!)
- A text editor like Windows Notepad or Notepad++
- Manually install Golang using zip distribution (not an installer) for Windows (currently Go1.18) from its download page.
- Some knowledge of DOS commands
- Some Golang environment variables
Then, download the Golang zip distribution and extract it to some local directory, e.g., C:\Users\karldev\Desktop\dev\apps\go\go1.18. Immediately beneath this directory have the following subdirectories.
1 2 3 4 5 6 | api bin doc go lib src |
Next, please take note of that directory because we will use it in the next section.
Manually Install Golang in Windows
Once we download the Golang zip distribution and extract its content to some directory, we open a Windows command line. Then, set the following environment variable the command-line window to the path we extracted the Golang binaries.
1 | GOROOT |
For example, run the following command.
1 | set GOROOT=C:\Users\karldev\Desktop\dev\apps\go\go1.18 |
Setting the GOROOT environment variable is not enough. When we try running the go executable anywhere, it will not work.
1 2 3 4 5 | C:\Users\karldev>set GOROOT=C:\Users\karldev\Desktop\dev\apps\go\go1.18 C:\Users\karldev>go 'go' is not recognized as an internal or external command, operable program or batch file. |
Next, we need to append the PATH environment variable with a directory to the Golang bin directory. To do so, run the following command.
1 | set PATH=%PATH%;%GOROOT%\bin |
When we run the go executable from the same command-line window, we get the following output indicating that Golang now works from the command-line window.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | C:\Users\karldev>set PATH=%PATH%;%GOROOT%\bin C:\Users\karldev>go Go is a tool for managing Go source code. Usage: go <command> [arguments] The commands are: bug start a bug report build compile packages and dependencies clean remove object files and cached files doc show documentation for package or symbol env print Go environment information fix update packages to use new APIs fmt gofmt (reformat) package sources |
IDEs use these, among others, two environment variables for configuration, allowing users to build and run Golang codes from within the code editors. For instance, GoLand uses the GOROOT variable to specify the path to the Golang SDK.
Using Golang Installer Instead?
If we do not want to deal with paths and DOS commands, we could use a Golang installer instead. Life is easier in this case, would you agree?