asdf-community/asdf-golang

cannot find GOROOT directory: /usr/lib/go

feluxe opened this issue ยท 9 comments

Describe the bug

I installed asdf-golang. When I run a go command I get an error.

To Reproduce

Steps to reproduce the behavior:

  1. $ asdf plugin-add golang https://github.com/kennyp/asdf-golang.git
  2. $ asdf install golang 1.12.1
  3. $ asdf global golang 1.12.1
  4. $ go run myfile.go

Error:

go: cannot find GOROOT directory: /usr/lib/go

Expected behavior

I expected go to work without the error.

Desktop (please complete the following information):

  • OS: Arch Linux
  • Version asdf v0.7.0

@feluxe Do you still have the issue? Can you supply the output of these commands for debug:

env | grep GOROOT
which go
go env GOROOT

@homburg Thanks for your reply!

Do you still have the issue?

Strange...I haven't changed anything since I reported, but I just tried again and it works now. So I think the issue was on my side. Sorry!

Anyways... I leave the output of your commands here, in case anyone runs into the same issue:

$ env | grep GOROOT
# Returns nothing
$ which go
/home/peter/.asdf/shims/go
$ go env GOROOT
/home/peter/.asdf/installs/golang/1.11.6/go

Hope it helps...

You're welcome! Thanks for the update.

Everything looks correct, might have been a PATH/rehash issue

I have the same issue
can somenody help me
I have this results:
go build main.go
go: cannot find GOROOT directory: /usr/lib/go

env | grep GOROOT
GOROOT=/usr/lib/go

which go
/usr/local/go/bin/go

go env GOROOT
go: cannot find GOROOT directory: /usr/lib/go

I have the same issue
can somenody help me
I have this results:
go build main.go
go: cannot find GOROOT directory: /usr/lib/go

env | grep GOROOT
GOROOT=/usr/lib/go

which go
/usr/local/go/bin/go

go env GOROOT
go: cannot find GOROOT directory: /usr/lib/go

@ferismed Restarting the shell worked for me

@feluxe Do you still have the issue? Can you supply the output of these commands for debug:

env | grep GOROOT
which go
go env GOROOT

env | grep GOROOT
GOROOT=/usr/lib/go

which go
/usr/local/go/bin/go

go env GOROOT
go: cannot find GOROOT directory: /usr/lib/go

#need_help

I'm also running into this. I have a workaround in my .zshrc:

export GOROOT=$(asdf where golang)/go

However, this will break anytime I change directory somewhere that has a new .tool-versions file.

This was happening to me. I had an incorrect version in the .tool-versions file. I had 1.18.0 and changing it to 1.18 fixed it. Hope that helps

sneko commented

Can we reopen this? Having the same issue...

It was working great before using asdf but now when generating some Go files (with gqlgen in my case) I get:

go generate ./...
pkg: go/build: go list github.com/99designs/gqlgen: exit status 2
go: cannot find GOROOT directory: /usr/local/go


resolver/resolver.go:1: running "gorunpkg": exit status 1
make: *** [graphql] Error 1

I expect asdf-golang to correctly set $GOROOT each time a folder is entered (the folder being either compatible with legacy versioning or .tool-versions).

@pokstad did you find a way to make it auto-updated for each folder?

Thank you,

EDIT: I switched to the way of generating with go run github.com/99designs/gqlgen generate directly instead of the "old" //go:generate go run github.com/99designs/gqlgen + go generate ./... and it works properly.