Need some help about go install

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.

Hi jtr109,
Not exactly sure what is causing your timeout issue. However, I think your GOBIN is setup incorrectly. I believe it should be:

GOBIN=$GOPATH/bin

For example, here is my GOPATH and GOBIN:

GOBIN="/home/andrew/go-workspace/bin"

GOPATH="/home/andrew/go-workspace"

Reference: https://golang.org/cmd/go/#hdr-GOPATH_environment_variable

1 Like

Hi, Andrew:

Thanks for you replication and I had a try.

But unfortunately, I cannot vanish the issue. Is there anything I did wrong?

What I did

First, I changed my ~/.zshrc like below:

export GOROOT=/usr/local/go
export GOBIN=$GOPATH/bin
export GOPATH=$HOME/gopath
export PATH=$GOPATH/bin:$PATH:$GOROOT/bin

Then I try to launch a new terminal and run go install:

$ sudo go install github.com/ramya-rao-a/go-outline
Password:
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 found the second path is still wrong. So I check my go env:

$ go env
GOARCH="amd64"
GOBIN="/Users/jtr109/gopath/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-build326999870=/tmp/go-build -gno-record-gcc-switches -fno-common"

More information

The output above shows the GOBIN has be changed as expected. Can the PATH output below provide more information?

$ echo $PATH
/urs/local/opt/node@8/bin:/urs/local/opt/curl/bin:/usr/local/opt/sqlite/bin:/Users/jtr109/gopath/bin:/usr/local/opt/libressl/bin:/usr/local/bin:/Users/jtr109/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/opt/X11/bin:/Applications/Wireshark.app/Contents/MacOS:/urs/local/opt/node@8/bin:/urs/local/opt/curl/bin:/usr/local/opt/sqlite/bin:/usr/local/opt/libressl/bin:/Users/jtr109/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/usr/local/opt/redis-3.2.6/src:/usr/local/mysql/bin:/Applications/Postgres.app/Contents/Versions/9.6/bin:/usr/local/opt/fzf/bin:/usr/local/opt/redis-3.2.6/src:/usr/local/mysql/bin:/Applications/Postgres.app/Contents/Versions/9.6/bin:/usr/local/go/bin

You may get the timeout error again, but try getting the dependency golang.org/x/tools/go/buildutil using go get -u. If that succeeds, then install the go-outline package. If the timeout error occurs, there is something preventing you from accessing that package. Try getting another package from golang.org just to see if it affects the buildutil only. However, your GOBIN is ok now.

Thanks for you help.

I deduce the timeout issue can be image as a network problem. And the go get command is just clone the repository and go install is automatically. So I prefer to achieve my goal by using go install temporarily.

The main.go of github.com/ramya-rao-a/go-outline just has a simple usage of import to get the builduitl. So I still think the error of go install is my fault.

I also had a try on go get to the repository and it might not work well:

$ 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)

So maybe anything else I can try to solve the wrong path of my go install? Or maybe it is a misunderstand of it?

I also found an other thing weird:

I tried to have a test to go build the package and I found it can find the correct GOPATH:

$ go build -v -o ./try-buildutil gihub.com/ramya-rao-a/go-outline
can't load package: package gihub.com/ramya-rao-a/go-outline: cannot find package "gihub.com/ramya-rao-a/go-outline" in any of:
        /usr/local/go/src/gihub.com/ramya-rao-a/go-outline (from $GOROOT)
        /Users/jtr109/gopath/src/gihub.com/ramya-rao-a/go-outline (from $GOPATH)

But it fell into disorder again if I try to go install the package when the package import the buildutil

➜  gopl sudo go install github.com/ramya-rao-a/go-outline
Password:
../../../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)

Thanks a lot to Andrew!

My issue which cannot find correct GOPATH seem to be solved! I uninstalled my GO and remove the file like the document says:

If you installed Go with the Mac OS X package then you should remove the /etc/paths.d/go file.

Then I reinstall by .pkg and make sure my GOROOT, GOPATH and GOBIN set correctly.

And now, everything works well!

The timeout while go get the go-outline package may still be a problem. But I have solved the problem I have to!

Thanks for you help!

Reference: https://golang.org/cmd/go/#hdr-Compile_and_install_packages_and_dependencies

Just an FYI, go install does not download the dependencies of the package you are trying to install. Therefore, since you cloned the github.com/ramya-rao-a/go-outline locally and you’re running go install, the dependency golang.org/x/tools/go/buildutil is not being fetched. hence the reason you receive:

cannot find package "golang.org/x/tools/go/buildutil" in any of:

There is a flag -i for go install that will install dependencies, but based on the docs, I don’t believe it downloads the dependencies of the package you are tying to install.

However, your main issue now seems to be an issue accessing the golang.org/x/tools/go/buildutil package for whatever reason, which is why you receive a timeout error when you run go get -v -u github.com/ramya-rao-a/go-outline (remember go get also fetches dependencies of the package).

Yes, I think you are right.

Maybe when I go install the go-outline, the golang searched my path for dependency buildutil and it cannot find it in wrong path. After I uninstall all about golang and reinstall it and make sure the config correct. The golang can find the dependency buildutil from my path $GOPATH/src/golang.org/x/tools/go/buildutil and everything works well.

Thanks for your tips about go install too! :kissing_heart:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.