Go install: "Unable to download package" (even if GOPATH is installed)

I am just getting started with the Go programming language and install Go using the Windows Installer from the website. I tested the installation with help go run hello.go

and it works. The problem comes when I try to create my first program:

$ echo $GOROOT
C:\Go\
$ echo $GOPATH
/cygdrive/c/Users/Paul/Documents/Home/go
mkdir -p $GOPATH/src/hello

      

Inside this directory, I have a simple program hello.go

:

package main

import "fmt"

func main() {
    fmt.Printf("Hello, world.\n")
}

      

The problem comes up when I try to build and install:

$ go install hello
can't load package: package hello: cannot find package "hello" in any of:
    C:\Go\src\hello (from $GOROOT)
    \cygdrive\c\Users\Paul\Documents\Home\go\src\hello (from $GOPATH)

      

+3


source to share


1 answer


GOPATH

the environment variable must contain a valid path.

\cygdrive\c\Users\Paul\Documents\Home\go\src\hello

is not a valid path on Windows.



Try installing GOPATH=c:\Users\Paul\Documents\Home\go

instead.

+2


source







All Articles