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
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.
mkdir gotown, then
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.
GOPATHinto the “Variable name” field.
C:\gotowninto the “Variable value” field.
- Click OK.
Setting Environmental Variables on macOS and other UNIX systems.
~/.bash_profile to add the following line:
Save and exit your editor. Then, source your
Check your GOPATH
This is done by simply typing
This will bring up details of the GOPATH and other folders such as bin, GOROOT, and other details.