19

I am new to GO and getting an error when initializing GOPATH in windows. In my project folder is

C:\Users\kamin\Documents\pm-manager

and i am try to set path in environment variable (GOPATH)but it is getting an error go: GOPATH entry is relative; must be absolute path: ":/cygdrive/c/Users/kamin/Documents/pm-manager\r\r". Run 'go help gopath' for usage.

3
  • 1
    Apparently you're using Cygwin, which you didn't mention anywhere in your question. Why not just run go from a regular Windows cmd window?
    – Michael
    Mar 9, 2016 at 7:01
  • @Michael i used Cygwin for build .sh file in a project Mar 9, 2016 at 7:03
  • 1
    Go under cygwin works perfectly fine all you have to remember is one thing: If you use a Windows Go installation it expects a Windows GOPATH which means: 1: No ':' to separate entries (I think it's ';' on Win) and 2: Use Windows paths like c:\User\kamin. That's all.
    – Volker
    Mar 9, 2016 at 9:13

5 Answers 5

14

Ran into same problem. Fix is quite simple: just specify the drive in front of the entire path name. The issue occurred because I was following the instructions on Go "Getting Started" page and set GOPATH=%HOMEPATH%\Work . The problem was that %HOMEPATH% was defined as a relative path (\Users\MyName), and so GOPATH now pointed to \Users\MyName\Work . All I needed to do was set GOPATH=c:\Users\MyName\Work and the error goes away.

3
  • 1
    @sandun-tharaka if the solution resolved your issue please mark it as correct answer.
    – LNI
    May 28, 2016 at 20:46
  • 1
    extra note: If GOPATH is set in cygwin (in .bashrc) then change "\" to "/"
    – R71
    Dec 19, 2016 at 12:06
  • In Linux, I tried export GOPATH=$/media/storage/gocode and got this error. I needed to remove dollar sign. It needs absolute path. So I did export GOPATH=/media/storage/gocode and it worked.
    – Hrvoje T
    Jan 2, 2019 at 14:07
7

I encountered the same problem. My go version is go1.9.1 windows/amd64. However I fixed the problem by deleting the simucolon end of the GOPATH. enter image description here

0
1

As alternative you can set it to %USERPROFILE%\ under Windows 10

1

you can put this case uses cygwin this go path

export GOPATH='c:\folder\folder\folder\'

for cygwin is necessary in string 'c:\path'

normaly you try use /cygdrive/.../...

but for GO is not possible ( need c:\ or other drive )

1

Adding one more error case that I experienced, was a silly-silly mistake in setting the GOPATH.

I added : D\Go (Forgot to added the colons after Drive letter). Correct should have been D:\Go, Offcourse this resolved the error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.