rbtLong
rbtLong

Reputation: 1572

Error When Issuing `go install`

I'm in my go root path and I get error the following errors when I perform the go install command...

main.go:4:2: cannot find package "fmt" in any of:
    /usr/lib/go-1.6/bin/src/fmt (from $GOROOT)
    /home/rbtlong/go/src/fmt (from $GOPATH)
main.go:6:2: cannot find package "io/ioutil" in any of:
    /usr/lib/go-1.6/bin/src/io/ioutil (from $GOROOT)
    /home/rbtlong/go/src/io/ioutil (from $GOPATH)
main.go:5:2: cannot find package "net/http" in any of:
    /usr/lib/go-1.6/bin/src/net/http (from $GOROOT)
    /home/rbtlong/go/src/net/http (from $GOPATH)
package rbtlong.com
    imports runtime: cannot find package "runtime" in any of:
    /usr/lib/go-1.6/bin/src/runtime (from $GOROOT)
    /home/rbtlong/go/src/runtime (from $GOPATH)

I have tried unsetting the GOROOT, but it doesn't seem to work.

Upvotes: 0

Views: 1643

Answers (3)

manikanta p.s
manikanta p.s

Reputation: 171

Before doing go install check for the Go version and Go path, if these are correct you won't get any error.

Please, install Go latest version from the official website and re-try once.

Upvotes: 0

rbtLong
rbtLong

Reputation: 1572

apparently, the definition was defined in $HOME/.bashrc after removing the definition for GOPATH and GOROOT, then manually removing the folder at /usr/lib/go-1.6 then reinstalling it using the instructions here https://golang.org/doc/install#install then setting the PATH and GOPATH by editing $HOME/.profile:

PATH="[...]:/usr/local/go/bin[...]"

export GOPATH="$HOME/go"

it appears to be working now...

Upvotes: 0

Kaedys
Kaedys

Reputation: 10138

Per discussion, it sounds like your install is a bit mucked up. Reinstalling Go seems to be the best option.

For others investigating GOROOT issues, the first step is almost always going to be to unset GOROOT. In most cases, GOROOT is not needed, and tends to muck up the works.

Another option for managing your Go installs more easily (and largely automagically), which also gives a homebrew-like version swapping capability and a containerization similar to virtualenv for Python or rvm for Ruby, is to use GVM.

Upvotes: 2

Related Questions