user2923605
user2923605

Reputation: 75

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

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)

Upvotes: 3

Views: 21491

Answers (1)

alex
alex

Reputation: 2248

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.

Upvotes: 3

Related Questions