5

Simple Go project, with a external dependence:

import (  
        "fmt"  
        "html"  
        "log"  
        "net/http"  
        "github.com/gorilla/mux"  
)

My path working fine for other tasks like run, build, etc.: GOPATH="/home/racar/go"

But when I try to get a external package with "go get" command, I got this error:

"go install: no install location for directory... outside GOPATH"

Edit: I have set my PATH in ~/.bashrc: export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

racar
  • 181
  • 1
  • 13
  • What is the path to your project? – JimB Jun 23 '17 at 17:14
  • Is your project within your `GOPATH`? – Adrian Jun 23 '17 at 18:21
  • Thanks. Edit the question with my path definition. In my project I can run other go commands so GOPATH seems ok. – racar Jun 23 '17 at 18:38
  • Could you review your workspace and directory layout with these references https://github.com/golang/go/wiki/GOPATH and https://github.com/golang/go/wiki/SettingGOPATH? – jeevatkm Jun 23 '17 at 19:04
  • Thanks @jeevatkm, second link pointed me the right direction. I set the GOBIN path and `go get` worked, `export GOBIN=$HOME/work/bin` – racar Jun 23 '17 at 23:27

1 Answers1

12

According with this link: github.com/golang/go/wiki/SettingGOPATH

Is needed to set GOBIN path in bash file: export GOBIN=$GOPATH/bin

Fito
  • 478
  • 4
  • 10
racar
  • 181
  • 1
  • 13
  • This really helped me after struggling with this error for two days. Thank you. – Peterson V Oct 27 '19 at 15:55
  • Even though the link no longer mentions `GOBIN`, I did have to set this environment variable, and doing so fixed the "no install location error". This was on Go 1.13.3. – Michael Herrmann Dec 26 '19 at 11:28