How to local import in non-local package error

I have the following file structure:

├── bin
│   └── hello
├── pkg
└── src
        ├── greeting
        │   └── greeting.go
        └── helloworld.go

5 directories, 3 files

With the following GOPATH


Upon executing /usr/local/go/bin/go install within the src folder, I get the error local import "./greeting" in non-local package


package main;
import "./greeting"

func main() {


You can’t use local import when specifying a non-local package to go install. If you want the local import to work, first change working directory to src/ then execute go install (without specifying the package).

Of course having the helloworld.go you provided you will get an compile error: imported and not used. But once you use something from the imported greeting package, it should compile.

But you shouldn’t use local imports at all. Instead write:

import ""

And doing so you will be able to compile/run/install it from anywhere.