02040402
02040402

Reputation: 799

Can't find GOPATH even set env path

Using the root user installed go on linux.

Set go path in the ~/.zshrc file:

export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
$ ls $HOME/go
bin pkg src

$ ls $HOME/go/bin
asmfmt  dlv  errcheck  fillstruct  gocode  gocode-gomod  godef  gogetdoc  goimports  golint  gometalinter  gomodifytags  gorename  gotags  gounit  guru  iferr  impl  keyify  motion

But go env returned:

zsh: command not found: go

Why?


Addition

$ whereis go
go: /usr/local/go

Set /usr/local to ~/.zshrc:

export PATH=$PATH:/usr/local/

Source it. Run go env returned:

zsh: permission denied: go

Upvotes: 0

Views: 601

Answers (1)

VonC
VonC

Reputation: 1323175

As commented, your ~/.zshrc should set PATH to reference Go, as seen in the Go wiki:

Edit your ~/.zshrc file to add the following line:

export GOPATH=$HOME/go

Save and exit your editor. Then, source your ~/.zshrc.

source ~/.zshrc

As explained in the default GOPATH and issue 17262, you don't need to set GOPATH.

But since Go 1.11 and its modules, you can now makes entire projects without ever using the default GOPATH at all: everything would remain local to your project.

As of Go 1.11, the go command enables the use of modules when the current directory or any parent directory has a go.mod, provided the directory is outside $GOPATH/src.
(Inside $GOPATH/src, for compatibility, the go command still runs in the old GOPATH mode, even if a go.mod is found)

Upvotes: 1

Related Questions