0

I've created a basic hello-world project which works fine. I now want to use godep, so I've added it to my project using go get github.com/tools/godep, which adds the godep to my src\github.com\tools folder. now when I run godep save command (no matter where I run it - either in the 'src' folder or inside the 'godep' folder itself) I get an error - 'godep' is not recognized as an internal or external command, operable program or batch file.

I have environment variables set to -

GOPATH = C:\Users\XXX\Documents\Go\helloWorld
GOROOT = C:\Go\

and the PATH includes C:\Go\bin and according to this I've also added GOBIN = C:\Go\bin However, I still get that error message.

what did I miss?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
eRez
  • 257
  • 8
  • 24
  • 3
    PATH must include $GOPATH/bin – Uvelichitel Mar 22 '18 at 10:57
  • thanks, but no change – eRez Mar 22 '18 at 11:06
  • @eRez `GOPATH = C:\Users\XXX\Documents\Go\helloWorld` is not whay you should do, `$GOPATH` should point to your Go [workspace](https://golang.org/doc/code.html#Workspaces), *not* your Go project. `$GOBIN` doesn't need to be set, downloaded packages that can be installed will be so automatically into `$GOPATH/bin`. Fix your env vars, make sure `$PATH` contains `$GOPATH/bin` as pointed out by @Uvelichitel, re-run `go get github.com/tools/godep` and try `godep save` again. – mkopriva Mar 22 '18 at 11:25
  • thanks @mkopriva. I followed your instructions, so now I have inside my main 'Go' folder (C:\Users\XXX\Documents\Go), bin, pkg & src folders. the src includes a 'hello' folder and 'github.com/tools/godep' folder, and after running `go install` command inside the 'godep' folder i got a 'godep.exe' inside the bin folder in the Go's root. at that point, if i run the `godep save` command from the Go's root folder i get this - – eRez Mar 22 '18 at 12:38
  • `C:\Users\xxx\Documents\Go>bin\godep save godep: [WARNING]: godep should only be used inside a valid go package directory and godep: [WARNING]: may not function correctly. You are probably outside of your $GOPATH. godep: [WARNING]: Current Directory: C:\Users\XXX\Documents\Go godep: [WARNING]: $GOPATH: C:\Users\XXX\Documents\Go godep: Unable to find SrcRoot for package .` – eRez Mar 22 '18 at 12:40
  • 1
    The message is pretty clear I think. You run `godep` commands inside of your project's root directory, i.e. inside `C:\Users\XXX\Documents\Go\src\hello`. Running `godep` outside of a Go project, makes little sense. You run `godep` inside the project for which you want to manage dependencies. Just like you would run git inside the project for which you want to version control the source. – mkopriva Mar 22 '18 at 12:42
  • what you wrote makes sense, however the only way I can make `godep save` to work from within 'hello' folder is if I use `C:\Users\XXX\Documents\Go\src\hello>%GOPATH%\bin\godep save`, otherwise its back to square one where i get `'godep' is not recognized...` error again – eRez Mar 22 '18 at 13:13
  • @eRez And you're certain that your `PATH` contains `GOPATH\bin`? Or `C:\Users\XXX\Documents\Go\bin` for that matter? If that's the case maybe try restarting your terminal? If that doesn't work I would say something's up with the shell you use. – mkopriva Mar 22 '18 at 13:42
  • It is the shell's job to resolve the location of a binary which you're trying to execute through said shell. If the binary resides in one of `PATH`'s directories the shell should be able to find it. – mkopriva Mar 22 '18 at 13:45
  • 2
    sorry, my bad - the `GOPATH\bin` inside `PATH` was misspelled :-( – eRez Mar 22 '18 at 14:13

0 Answers0