Hello everyone. I got a problem about go get
and go install
. I had tried every solution I can find from google and I though I cannot solve it by myself. So I try to ask your help.
Background information
I want to install a package github.com/ramya-rao-a/go-outline
$ sudo go get -v -u github.com/ramya-rao-a/go-outline
github.com/ramya-rao-a/go-outline (download)
Fetching https://golang.org/x/tools/go/buildutil?go-get=1
https fetch failed: Get https://golang.org/x/tools/go/buildutil?go-get=1: dial tcp 216.239.37.1:443: i/o timeout
package golang.org/x/tools/go/buildutil: unrecognized import path "golang.org/x/tools/go/buildutil" (https fetch: Get https://golang.org/x/tools/go/buildutil?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
I thought the GFW of China cause the timeout problem even though I have set ALL_PROXY
, http_proxy
and https_proxy
. So I gave up and try to install it by the offline source code.
Main problem
I cloned the repository from github:
$ git clone https://github.com/ramya-rao-a/go-outline $GOPATH/src/github.com/ramya-rao-a/go-outline
Cloning into '/Users/jtr109/gopath/src/github.com/ramya-rao-a/go-outline'...
remote: Counting objects: 35, done.
remote: Total 35 (delta 0), reused 0 (delta 0), pack-reused 35
Unpacking objects: 100% (35/35), done.
And try to install it by go install
command:
$ go install github.com/ramya-rao-a/go-outline
go/src/github.com/ramya-rao-a/go-outline/main.go:14:2: cannot find package "golang.org/x/tools/go/buildutil" in any of:
/usr/local/go/src/golang.org/x/tools/go/buildutil (from $GOROOT)
/Users/jtr109/go/src/golang.org/x/tools/go/buildutil (from $GOPATH)
I thought it is weird because the second is not my path. Here is my go environment which generated by go env
:
$ go env
GOARCH="amd64"
GOBIN="/usr/local/go/bin"
GOCACHE="/Users/jtr109/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/jtr109/gopath"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/qg/x7lv7ghs3qv1c85vkgyqgqy40000gn/T/go-build555607611=/tmp/go-build -gno-record-gcc-switches -fno-common"
So what cause the second path to find golang.org/x/tools/go/buildutil
is not $GOPATH//src/golang.org/x/tools/go/buildutil
but the unexpected path /Users/jtr109/go/src/golang.org/x/tools/go/buildutil (from $GOPATH)
?
Is there anything wrong in my settings?
FYI
Go version
$ go version
go version go1.10.3 darwin/amd64
My bashrc
export GOROOT=/usr/local/go
export GOPATH=$HOME/gopath
export PATH=$PATH:$GOPATH/bin:$GOROOT/bin
buildutil in my GOPATH
$ tree $GOPATH/src/golang.org/x/tools/go/buildutil
/Users/jtr109/gopath/src/golang.org/x/tools/go/buildutil
βββ allpackages.go
βββ allpackages_test.go
βββ fakecontext.go
βββ overlay.go
βββ overlay_test.go
βββ tags.go
βββ tags_test.go
βββ util.go
βββ util_test.go
βββ util_windows_test.go
0 directories, 10 files
Hope to get your generous help. Thanks a lot.