Re: How to set GOPATH in windows.

31,896 views
Skip to first unread message

Xu En

unread,
Dec 20, 2013, 11:50:01 PM12/20/13
to golan...@googlegroups.com
The magic google phrase is "set environmental variables windows"

I can give you the instructions for XP - in later versions the steps will be similar - but you'll probably need to look in a different place for "system"

ok..

1. Start >> Control Panel >> System >> ( at this point you should have a setting box that looks like the attached image number 1 ) (Right clicking on the "My Computer" icon if you have one, and selecting "properties" should also get you to this stage.

2. In the "Advanced Tab" click "Environmental variables" - ( now you should have a settings box like in the second attached image )

If you installed with the installer you will see a "GOROOT", but not a "GOPATH" - in the box "System variables" ( it's already been added in my screenshot) - now press new and enter "GOROOT" and where you want it.


2. Environment Variables.jpg
1. System Properties.jpg

John C.

unread,
Dec 21, 2013, 12:00:06 AM12/21/13
to golan...@googlegroups.com
Also, make sure you do not put spaces between directories listed in the path variable.

brainman

unread,
Dec 21, 2013, 12:29:31 AM12/21/13
to golan...@googlegroups.com
I don't fiddle with my global environment variables. I just have this small batch file

set GOROOT=c:\go\root
set GOPATH=c:\go\path
set PATH=%PATH%;c:\go\mingw64\bin;%GOROOT%\bin
cd %GOROOT%\src
CMD

If you put that file on your desktop and double click it, new windows will open and all environment variables will be set accordingly. Just modify it to match your system.

Alex

Richard Lyman

unread,
Dec 21, 2013, 12:36:15 AM12/21/13
to golan...@googlegroups.com
Getting to the Environment Variables dialog on Win. 7:

 1. Holding the Windows Key down, press the Pause/Break key. This brings up a window about your system
 2. Click the 'Advanced system settings' option in the left-hand panel. This brings up the System Properties dialog on the Advanced tab
 3. Click the Environment Variables button near the bottom right-hand corner. This dialog is where you can set variables like GOPATH

-Rich



--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Carlos Castillo

unread,
Dec 21, 2013, 1:31:09 AM12/21/13
to golan...@googlegroups.com
It is not a good idea to set GOPATH = GOROOT (ie: where go is installed), as you will be mixing stdlib code (which should be read-only) with your own code, and code you fetch with go get. After installing go to C:\Go you should never modify that folder or it's contents. Make a folder elsewhere where your user has write permission, and put that value in GOPATH (preferably for your user only).

On Friday, December 20, 2013 4:44:30 PM UTC-8, Sam Kirwen wrote:
I have been searching google for hours and I don't see why not a single one of the results say how to set $GOPATH in Windows. They say it needs to be set, and how to check if it's set but nowhere does it say HOW I set it.

I would be eternally grateful to anyone that can help, I feel like my mind is going to explode, this is so simple but nothing I do seems to work.

doing > go env confirms that my GOPATH is blank, I want to set it to C:\GO (where it is installed), how do I do this?

Thanks!

jaziri...@gmail.com

unread,
Feb 1, 2014, 8:38:17 AM2/1/14
to golan...@googlegroups.com
Hello!
what should be the value of GOPATH and what should i add to the  value of the variable PATH?

thanks!

brainman

unread,
Feb 1, 2014, 7:45:33 PM2/1/14
to golan...@googlegroups.com, jaziri...@gmail.com

dhan...@gmail.com

unread,
Feb 15, 2014, 4:31:31 AM2/15/14
to golan...@googlegroups.com, jaziri...@gmail.com
REM modified version of brainman's batch file at https://groups.google.com/forum/#!topic/golang-nuts/QVPKm7pbhds
 
REM setting goroot to my go installation folder.
set GOROOT=C:\go
 
REM setting gopath to my go playground folder
set GOPATH=C:\Users\****\goplayground
Set GOBIN=%GOPATH%\bin
set PATH=%PATH%;c:\go\bin;%GOBIN%
 
REM finally make my playground source folder as my PWD, write your hello.go here and execute "go install" and check GOBIN folder for exe.
cd %GOPATH%\src
CMD
Reply all
Reply to author
Forward
Message has been deleted
0 new messages