others-how to solve golang compile: version 'go1.14.2' does not match go tool version 'go1.14' ?

Problem

When we use install golang sdk ,sometimes ,we get this error:

** **memcached-operator** operator-sdk new memcached-operator

INFO[0000] Creating new Go operator 'memcached-operator'. 

INFO[0000] Created go.mod                

INFO[0000] Created tools.go               

INFO[0000] Created cmd/manager/main.go          

INFO[0000] Created build/Dockerfile           

INFO[0000] Created build/bin/entrypoint         

INFO[0000] Created build/bin/user_setup         

INFO[0000] Created deploy/service_account.yaml      

INFO[0000] Created deploy/role.yaml           

INFO[0000] Created deploy/role_binding.yaml       

INFO[0000] Created deploy/operator.yaml         

INFO[0000] Created pkg/apis/apis.go           

INFO[0000] Created pkg/controller/controller.go     

INFO[0000] Created version/version.go          

INFO[0000] Created .gitignore              

INFO[0000] Validating project              

\# math/bits

compile: version "go1.14.2" does not match go tool version "go1.14"

\# unicode/utf8

compile: version "go1.14.2" does not match go tool version "go1.14"

\# internal/race

compile: version "go1.14.2" does not match go tool version "go1.14"

\# unicode

compile: version "go1.14.2" does not match go tool version "go1.14"

\# runtime/internal/sys

compile: version "go1.14.2" does not match go tool version "go1.14"

\# encoding

compile: version "go1.14.2" does not match go tool version "go1.14"

\# unicode/utf16

compile: version "go1.14.2" does not match go tool version "go1.14"

\# internal/nettrace

compile: version "go1.14.2" does not match go tool version "go1.14"

\# crypto/subtle

compile: version "go1.14.2" does not match go tool version "go1.14"

\# container/list

compile: version "go1.14.2" does not match go tool version "go1.14"

\# crypto/internal/subtle

compile: version "go1.14.2" does not match go tool version "go1.14"

\# k8s.io/apimachinery/pkg/selection

compile: version "go1.14.2" does not match go tool version "go1.14"

\# k8s.io/utils/integer

compile: version "go1.14.2" does not match go tool version "go1.14"

\# vendor/golang.org/x/crypto/internal/subtle

compile: version "go1.14.2" does not match go tool version "go1.14"

\# vendor/golang.org/x/crypto/cryptobyte/asn1

compile: version "go1.14.2" does not match go tool version "go1.14"

\# sync/atomic

compile: version "go1.14.2" does not match go tool version "go1.14"

\# golang.org/x/xerrors/internal

compile: version "go1.14.2" does not match go tool version "go1.14"

\# github.com/google/go-cmp/cmp/internal/diff

compile: version "go1.14.2" does not match go tool version "go1.14"

\# github.com/google/go-cmp/cmp/internal/flags

compile: version "go1.14.2" does not match go tool version "go1.14"

\# github.com/go-logr/logr

compile: version "go1.14.2" does not match go tool version "go1.14"

\# runtime/internal/atomic

compile: version "go1.14.2" does not match go tool version "go1.14"

\# k8s.io/utils/buffer

compile: version "go1.14.2" does not match go tool version "go1.14"

\# memcached-operator/memcached-operator/version

compile: version "go1.14.2" does not match go tool version "go1.14"

\# github.com/coreos/prometheus-operator/pkg/apis/monitoring

compile: version "go1.14.2" does not match go tool version "go1.14"

\# internal/cpu

compile: version "go1.14.2" does not match go tool version "go1.14"

\# runtime/cgo

compile: version "go1.14.2" does not match go tool version "go1.14"

Error: failed to exec []string{"go", "build", "./..."}: exit status 2

The core error is :

compile: version "go1.14.2" does not match go tool version "go1.14"

Environment

  • MacOS 10.14
  • Golang go version go1.14 darwin/amd64

Reason

There are two golang versions in my system, we can verify as follows:

➜ /usr/local/go/bin/go version
go version go1.14.2 darwin/amd64

➜ /usr/local/Cellar/go/1.14/libexec/bin/go version
go version go1.14 darwin/amd64

So the problem is located.

Solution

We should change our GOROOT to the 1.14 version of go in my system, e.g. /usr/local/Cellar/go/1.14/libexec

Open .zshrc in my system, and change the GOROOT environment settings as follows:

export GOROOT=/usr/local/Cellar/go/1.14/libexec

Retart the terminal , and verify the go version as follows:

➜  ~ echo $GOROOT
/usr/local/Cellar/go/1.14/libexec
➜  ~ go version
go version go1.14 darwin/amd64
➜  ~ which go
/usr/local/bin/go
➜  ~ ls -l /usr/local/bin/go
lrwxr-xr-x  1 bswen  admin  24 Dec 14 20:36 /usr/local/bin/go -> ../Cellar/go/1.14/bin/go
➜  ~

Re-execute the command :

➜** **memcached-operator** operator-sdk new memcached-operator

INFO[0000] Creating new Go operator 'memcached-operator'. 

INFO[0000] Created go.mod                

INFO[0000] Created tools.go               

INFO[0000] Created cmd/manager/main.go          

INFO[0000] Created build/Dockerfile           

INFO[0000] Created build/bin/entrypoint         

INFO[0000] Created build/bin/user_setup         

INFO[0000] Created deploy/service_account.yaml      

INFO[0000] Created deploy/role.yaml           

INFO[0000] Created deploy/role_binding.yaml       

INFO[0000] Created deploy/operator.yaml         

INFO[0000] Created pkg/apis/apis.go           

INFO[0000] Created pkg/controller/controller.go     

INFO[0000] Created version/version.go          

INFO[0000] Created .gitignore              

INFO[0000] Validating project              

INFO[0018] Project validation successful.        

INFO[0018] Project creation complete.          

**➜** **memcached-operator** 

It works!

-->