Create the GOPATH Environment Variable in Windows

Create the GOPATH Environment Variable in Windows

Create or verify your GOPATH environmental variable in Windows OS, this important after installing Go on your system. The process involves verifying the location of the go folder, the path and also the bin folder inside the go folder. The three main folders that needs to reside in the Go folder includes the bin, pkg, and src folder. They each have their roles and function within the golang ecosystem.

Setting GOPATH for a Custom Location on Windows

The default GOPATH location for go installation is the %USERPROFILE%\go on windows system. This is usually C:\Go on most windows system, you will find the bin folder in the following PATH C:\Go\bin.

Since Go version 1.8 the GOPATH can be any directory on the windows system. Once you change the default settings you need to update the environmental variable manually or through CLI.

The process is quite simple we would create a folder and name it gotown.

Open your Command Prompt and create a folder on the root directory.

Type mkdir gotown, then cd gotown.

Your root should look like this C:\gotown

or do this manually by:

  • Create a folder at at the root C:\. called it gotown.
  • Right click on “Start” and click on “Control Panel”. Select “System and Security”, then click on “System”.
  • From the menu on the left, select the “Advanced systems settings”.


Type environment in the search box, this will bring up the environment variables.

Select Edit environmental variables and follow the instruction below.

  • Click the “Environment Variables” button at the bottom.
  • Click “New” from the “User variables” section.
  • Type GOPATH into the “Variable name” field.
  • Type C:\gotown into the “Variable value” field.
  • Click OK.

Setting Environmental Variables on macOS and other UNIX systems.

Edit your ~/.bash_profile to add the following line:

export GOPATH=$HOME/go

Save and exit your editor. Then, source your ~/.bash_profile.

source ~/.bash_profile

Check your GOPATH

This is done by simply typing go env

This will bring up details of the GOPATH and other folders such as bin, GOROOT, and other details.


Post Comment