98

I'm trying to install a web.go, but running go get github.com/hoisie/web returns

package bufio: unrecognized import path "bufio"
package bytes: unrecognized import path "bytes"
package crypto/rand: unrecognized import path "crypto/rand"
package crypto/sha1: unrecognized import path "crypto/sha1"
package crypto/tls: unrecognized import path "crypto/tls"
package encoding/base64: unrecognized import path "encoding/base64"
package encoding/binary: unrecognized import path "encoding/binary"
package encoding/json: unrecognized import path "encoding/json"
package errors: unrecognized import path "errors"
package fmt: unrecognized import path "fmt"

and this continues for a while with various packages, before returning nothing else. go env gives me:

GOARCH="amd64"
GOBIN="/usr/local/go/bin"
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=""
GORACE=""
GOROOT="/home/me/go"
GOTOOLDIR="/home/me/go/pkg/tool/linux_amd64"
TERM="dumb"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
CXX="g++"
CGO_ENABLED="1"

How can I install web.go? Using go get (rather than go install) is what is in the README on the github page. My Go version is go version go1.2 linux/amd64.

q3d
  • 3,473
  • 8
  • 34
  • 39
  • 4
    Exported GOROOT but no GOPATH? GOROOT differs from GOBIN? How did you install Go? How did you set up your environment? – Volker Dec 08 '13 at 20:49
  • I installed go by following the http://golang.org/doc/install page. I wasn't sure what to put for GOPATH. – q3d Dec 08 '13 at 21:00

9 Answers9

110

The issues are relating to an invalid GOROOT.

I think you installed Go in /usr/local/go.
So change your GOROOT path to the value of /usr/local/go/bin.

It seems that you meant to have your workspace (GOPATH) located at /home/me/go.

This might fix your problem.
Add this to the bottom of your bash profile, located here => $HOME/.profile

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

Make sure to remove the old references of GOROOT.

Then try installing web.go again.

If that doesn't work, then have Ubuntu install Go for you.

sudo apt-get install golang

Video tutorial: http://www.youtube.com/watch?v=2PATwIfO5ag

FrozenDroid
  • 166
  • 13
Larry Battle
  • 9,008
  • 4
  • 41
  • 55
  • 17
    You should almost never set GOROOT. Your PATH declaration doesn't hit /usr/local/go/bin. Also, should note that the ubuntu packages are a bit behind the official release, which is 1.2. – JimB Dec 09 '13 at 15:08
  • 2
    When I followed the go install instructions from the official site (install from the tar file into /usr/local) I received the error above until I changed the GOROOT as above. – Drew Apr 10 '14 at 17:38
  • 1
    Just installed fresh golang 1.3 on fedora 20 and `go get` gives the same error. `GOROOT` is set to `/usr`, go itself installed into /usr, not /usr/local. Set `GOPATH` to `$HOME/go`. Any idea what else to check ? – Dfr Dec 02 '14 at 15:45
  • 15
    Answering to myself: unsetting `GOROOT` seem fixed the problem. – Dfr Dec 02 '14 at 15:56
  • Installing `golang` from apt, instead of `gccgo-go` seems to have resolved this for me. – ThorSummoner Mar 24 '15 at 16:26
  • 5
    +1 for not setting GOROOT. I unset it, made sure it was unset with `echo $GOROOT` then checked that GO still had it in the env with `go env` which it did and it was at `/usr/local/go` where I have go installed (thus no need to set it in any case) – Michael M Jul 02 '15 at 23:04
  • Using GoClipse I was struggling to select proper `GOROOT` in fedora 23. Using `go env` as advised by @Michael.M helped (and value was `/usr/lib/golang`). Thanks! – akostadinov Feb 14 '16 at 16:28
  • It's amazing how difficult it is to install Go. – Philippe Delteil Jun 04 '21 at 21:47
39

I installed Go with brew on OSX 10.11, and found I had to set GOROOT to:

/usr/local/Cellar/go/1.5.1/libexec

(Of course replace the version in this path with go version you have)

Brew uses symlinks, which were fooling the gotool. So follow the links home.

Greg Dubicki
  • 5,983
  • 3
  • 55
  • 68
Eric
  • 2,115
  • 2
  • 20
  • 29
23

I had exactly the same issue, after moving from old go version (installed from old PPA) to newer (1.2.1) default packages in ubuntu 14.04.

The first step was to purge existing go:

sudo apt-get purge golang*

Which outputs following warnings:

dpkg: warning: while removing golang-go, directory '/usr/lib/go/src' not empty so not removed
dpkg: warning: while removing golang-go.tools, directory '/usr/lib/go' not empty so not removed

It looks like removing go leaves some files behind, which in turn can confuse newer install. More precisely, installation itself will complete fine, but afterwards any go command, like "go get something" gives those "unrecognized import path" errors.

All I had to do was to remove those dirs first, reinstall golang, and all works like a charm (assuming you also set GOPATH)

# careful!
sudo rm -rf /usr/lib/go /usr/lib/go/src
sudo apt-get install golang-go golang-go.tools
jareks
  • 360
  • 2
  • 7
8

$ unset GOROOT worked for me. As most answers suggest your GOROOT is invalid.

noelmcloughlin
  • 1,723
  • 1
  • 12
  • 10
7

Because GFW forbidden you to access golang.org ! And when i use the proxy , it can work well.

you can look at the information using command go get -v -u golang.org/x/oauth2

jefby
  • 345
  • 1
  • 4
  • 14
  • 1
    This is exactly the problem I have as I'm in China. After setting $http_proxy, I can install the package without error. – ashen Feb 28 '16 at 00:31
  • 1
    Not only blocked, but also the DNS is polluted. First go to `http://ping.eu/nslookup/` to find the correct IP of the domain, set that into hosts file, then use a proxy to download.`export http_proxy=127.0.0.1:1080 https_proxy=127.0.0.1:1080` Sometimes you just want to say the F word to the Gov – Mr.Wang from Next Door Mar 14 '16 at 13:09
2

I had the same problem on MacOS 10.10. And I found that the problem caused by OhMyZsh shell. Then I switched back to bash everything went ok.

Here is my go env

bash-3.2$ go env
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/bis/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1
Igor Barinov
  • 21,820
  • 10
  • 28
  • 33
  • Is that `go env` from the when it didn't work or when it did? It probably wasn't "caused by [other shell]", rather it was likely a failure to correctly set `GOPATH` in that other shell. The csh and zsh family of shells do *not* use the same startup files (i.e. no `~/.profile`). In particular `zsh` uses `$ZDOTDIR/.zshenv` and `$ZDOTDIR/.zprofile` (where `$ZDOTDIR` defaults to `$HOME`). – Dave C Mar 26 '15 at 16:10
2

The most common causes are:
1. An incorrectly configured GOROOT
OR
2. GOPATH is not set

Clyde D'Cruz
  • 1,915
  • 1
  • 14
  • 36
0

I had the same issue after having upgraded go1.2 to go1.4.

I renamed src to _src in my GOPATH then did a go get -v

It worked then I deleted _src.

Hope it helps.

Amaury Brisou
  • 344
  • 1
  • 4
  • 10
0

I encountered this issue when installing a different package, and it could be caused by the GOROOT and GOPATH configuration on your PATH. I tend not to set GOROOT because my OS X installation handled it (I believe) for me.

  1. Ensure the following in your .profile (or wherever you store profile configuration: .bash_profile, .zshrc, .bashrc, etc):

    export GOPATH=$HOME/go
    export PATH=$PATH:$GOROOT/bin
    
  2. Also, you likely want to unset GOROOT, as well, in case that path is also incorrect.

  3. Furthermore, be sure to clean your PATH, similarly to what I've done below, just before the GOPATH assignment, i.e.:

    export PATH=$HOME/bin:/usr/local/bin:$PATH
    export GOPATH=$HOME/go
    export PATH=$PATH:$GOROOT/bin
    
  4. Then, source <.profile> to activate

  5. retry go get
ThatsAMorais
  • 659
  • 8
  • 16