cannot find package “github.com/gorrila/mux” in any of
cannot find package “github.com/gorrila/mux” in any of
The error message is:
app.go:9:3: cannot find package "github.com/gorrila/mux" in any of:
/usr/local/Cellar/go/1.10.3/libexec/src/github.com/gorrila/mux (from
$GOROOT)
/Users/myname/go/src/github.com/gorrila/mux (from $GOPATH)
I understand GOROOT is for compiler tools that come with installation, so I am not sure why it looks for mux there. But I do see mux in the second location in my directory I created for go code.
I know this question was asked once before and I tried to debug following the advice from that question.
I used homebrew and installed go version go1.10.3 darwin/amd64
.
go1.10.3 darwin/amd64
Here is what I believe to be the relevant portion of my go env:
GOPATH="/Users/myname/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.10.3/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.10.3/libexec/pkg/tool/darwin_amd64"
I also set my bash profile, excluding GOROOT because that is no longer required:
export GOPATH="/Users/myname/go/src/github.com"
export PATH="/Users/myname/go/src/github.com/bin:$PATH"
And did source ~/.bash_profile
.
source ~/.bash_profile
This setup was enough that I can run basic go programs like hello world. So I then tried to run code using the mux
library.
mux
I first installed mux within the directory of my program (cd'd into /Users/myname/go/src/github.com/myname/restapi
).
/Users/myname/go/src/github.com/myname/restapi
Then I ran:
go get -u github.com/gorilla/mux
I can see the folder exists in my finder. I also looked in terminal:
ls -l /Users/myname/go/src/github.com | grep gorilla
=> drwxr-xr-x 3 myname staff 102 Jun 29 14:35 gorilla
Then:
cd $GOPATH (/Users/myname/go)
go list ... | grep gorilla
=> can't load package: package ../..: no Go files in /Users
So I saw gorilla in the first command but not the second. However, I do see the gorilla directory further within my go directory, so I'm not sure what the issue is.
Running go build
returns the package of concern:
go build
app.go:9:3: cannot find package "github.com/gorrila/mux" in any of:
/usr/local/Cellar/go/1.10.3/libexec/src/github.com/gorrila/mux
(from $GOROOT)
/Users/myname/go/src/github.com/gorrila/mux (from $GOPATH)
I am not sure why it is looking for mux within the usr directory. Is there an issue with any of my paths? I keep checking that last path to see that the mux directory is there.
go list
GOPATH
/Users/myname/go/src/github.com/gorrila/mux
.go
@JimB Looking in my directory in the terminal I see that
/Users/myname/go/src/github.com/gorrila/mux
does exist and it contains files like mux.go, mux_test.go, route.go, etc– user9503053
Jun 29 at 22:39
/Users/myname/go/src/github.com/gorrila/mux
2 Answers
2
It looks like you misspelled "github.com/gorilla/mux"
– it has one "r" and two "l"'s. (Carefully compare the go get
command you quoted and the import
statement in your source file.)
"github.com/gorilla/mux"
go get
import
Got it, I did misspell the toolkit in my file. Thank you.
– user9503053
2 days ago
Can you try to set your .bash_profile
in this way:
.bash_profile
export GOPATH=$HOME/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN
Hi, I set that exactly within my
.bash_profile
and am receiving the identical error as listed above.– user9503053
Jun 30 at 4:13
.bash_profile
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Packages are looked up in GOROOT first, because that's where the stdlib lives.
go list
doesn't work at the root ofGOPATH
because the go tool works on packages. Does the directory/Users/myname/go/src/github.com/gorrila/mux
actually exist, and does it contain.go
files?– JimB
Jun 29 at 22:35