go: no such tool “compile” (a bad experience)

This is a record of outrageous problems and inexplicable solutions

Background: Under the win11 system, after the original go1.18 was updated to go1.19, an inexplicable go: no sucn tool "compile" appeared.

Check go env at that time, as follows:

PS D:\Desktop> go env
set GO111MODULE=off
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\user\AppData\Local\go-build
set GOENV=C:\Users\user\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=D:\documents\gocourse\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=D:\software\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=D:\documents\gocourse
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=D:\software\go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.19.2
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set GOWORK=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\user\AppData\Local\Temp\go-build126469990=/tmp/go-build -gno-record-gcc-switches

Interpretation: the above gocourse directory is where my old version of the go project is located, and the go folder under the software is the installation path of go, so logically speaking, GOPATH should be the project path, and then GOROOT should be the installation path. But after the new version is installed, everything is reversed. Even the GOTOOLDIR parameter is messed up.

In addition, the place where the above error occurs is actually a simple hello primary package test, and I report this error directly when I run it.

PS D:\Desktop>go run test.go
go: no sucn tool "compile"
go: no sucn tool "compile"
go: no sucn tool "compile"

Regarding the compile package, it is actually the corresponding series of software under the pkg package in the installation path. For windows, it is windows_amd64, and for linux, it is parameters such as linux_amd64.

toss start

According to the tips of certain netizens, I found the old version of go to reinstall. Of course, the original go version was uninstalled first. In addition, the env setting file is saved in a special path, which also needs to be deleted. The file path is C :\Users\penta\AppData\Roaming\go under the env file. Because the new version already has a relatively complete ecology, you can uninstall the program directly on the control panel. After the uninstallation is complete, delete a batch of environment variables by the way. Re-open the win11 terminal.
insert image description here
Right-click to open the terminal, check the version again, um, the version is ok, check the parameters, OH! My eye!

PS D:\Desktop> go env
set GO111MODULE=off
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\user\AppData\Local\go-build
set GOENV=C:\Users\user\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=D:\documents\gocourse\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=D:\software\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=D:\documents\gocourse
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=D:\software\go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.18.7
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set GOWORK=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\user\AppData\Local\Temp\go-build126469990=/tmp/go-build -gno-record-gcc-switches

continue to toss

No way, then modify the settings,

PS D:\Desktop>go env -w GOPATH=D:\documents\gocourse
go env -w GOPATH=... does not override conflicting OS environment variable

Um? What the hell is this, why is it not allowed to be modified. Continue to Baidu. . . . . . There is no useful information, it is called unset GOPATH, but the system does not recognize your command! It doesn't work here, so customize it directly in the user variable.
insert image description here
I thought, this is always okay, right? Well, continue to go env
^%$&%*((, it’s just a curse, and then a netizen has another suggestion, use the super user mode to set this parameter, well, the administrator opens cmd, first look at the parameters, go env, Um......

C:\Windows\system32>go env
set GO111MODULE=off
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\user\AppData\Local\go-build
set GOENV=C:\Users\user\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=D:\documents\gocourse\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=D:\documents\gocourse
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=D:\software\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=D:\software\go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.18.7
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set GOWORK=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\user\AppData\Local\Temp\go-build126469990=/tmp/go-build -gno-record-gcc-switches

Wouldn't this be changed? Why is powershell not updated? ? ? ? ? There is no way, so I have to restart it, um, okay. Run it:

PS D:\Desktop> go run test.go
Hello, I' m your father.

Really are. . . . . .

Guess you like

Origin blog.csdn.net/weixin_44948269/article/details/127613670