Go install: “Can't load package” (even though GOPATH is set)

19,233

GOPATH environment variable must contain valid path.

\cygdrive\c\Users\Paul\Documents\Home\go\src\hello is not a valid path on Windows.

Try setting GOPATH=c:\Users\Paul\Documents\Home\go instead.

Share:
19,233
user2923605
Author by

user2923605

Updated on June 04, 2022

Comments

  • user2923605
    user2923605 about 2 years

    I'm just getting started with the Go programming language and installed Go using the Windows installer from the website. I tested installation by using go run hello.go and that works. The problem comes when I try to build my first program:

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

    Inside that directory I have a simple hello.go program:

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

    The problem comes 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)