<p>My OS is <code>ubuntu 14.04.3</code> Server, and I want to build <code>kubernetes</code>.</p>

<p>Firstly, I use "<code>apt-get</code>" command install <code>Golang</code>, but the version is <code>1.2.1</code>, so I  use <code>apt-get --purge autoremove</code> command to remove it.And install the newest <code>1.5.1</code> from golang website.</p>

<p>But executing <code>make</code> command, it seems <code>kubernetes</code> always "think" current <code>golang</code> is <code>1.2.1</code>:</p>

<pre><code>$ make
hack/build-go.sh
+++ [1203 06:20:30] Building go targets for linux/amd64:
    cmd/kube-proxy
    cmd/kube-apiserver
    cmd/kube-controller-manager
    cmd/kubelet
    cmd/kubemark
    cmd/hyperkube
    cmd/linkcheck
    plugin/cmd/kube-scheduler
    cmd/kubectl
    cmd/integration
    cmd/gendocs
    cmd/genkubedocs
    cmd/genman
    cmd/mungedocs
    cmd/genbashcomp
    cmd/genconversion
    cmd/gendeepcopy
    cmd/genswaggertypedocs
    examples/k8petstore/web-server/src
    github.com/onsi/ginkgo/ginkgo
    test/e2e/e2e.test
+++ [1203 06:20:30] +++ Warning: stdlib pkg with cgo flag not found.
+++ [1203 06:20:30] +++ Warning: stdlib pkg cannot be rebuilt since /usr/local/go/pkg is not writable by nan
+++ [1203 06:20:30] +++ Warning: Make /usr/local/go/pkg writable for nan for a one-time stdlib install, Or
+++ [1203 06:20:30] +++ Warning: Rebuild stdlib using the command 'CGO_ENABLED=0 go install -a -installsuffix cgo std'
+++ [1203 06:20:30] +++ Falling back to go build, which is slower
    # k8s.io/kubernetes/pkg/util/yaml
_output/local/go/src/k8s.io/kubernetes/pkg/util/yaml/decoder.go:26: import /home/nan/kubernetes/Godeps/_workspace/pkg/linux_amd64/github.com/ghodss/yaml.a: object is [linux amd64 go1.2.1 X:none] expected [linux amd64 go1.5.1 X:none]
# k8s.io/kubernetes/pkg/util/validation
_output/local/go/src/k8s.io/kubernetes/pkg/util/validation/errors.go:23: import /home/nan/kubernetes/_output/local/go/pkg/linux_amd64/k8s.io/kubernetes/pkg/util/errors.a: object is [linux amd64 go1.2.1 X:none] expected [linux amd64 go1.5.1 X:none]
# k8s.io/kubernetes/pkg/api/resource
_output/local/go/src/k8s.io/kubernetes/pkg/api/resource/quantity.go:27: import /home/nan/kubernetes/Godeps/_workspace/pkg/linux_amd64/speter.net/go/exp/math/dec/inf.a: object is [linux amd64 go1.2.1 X:none] expected [linux amd64 go1.5.1 X:none]
# github.com/spf13/cobra
Godeps/_workspace/src/github.com/spf13/cobra/command.go:27: import /home/nan/kubernetes/Godeps/_workspace/pkg/linux_amd64/github.com/inconshreveable/mousetrap.a: object is [linux amd64 go1.2.1 X:none] expected [linux amd64 go1.5.1 X:none]
# k8s.io/kubernetes/pkg/util/iptables
_output/local/go/src/k8s.io/kubernetes/pkg/util/iptables/iptables.go:27: import /home/nan/kubernetes/Godeps/_workspace/pkg/linux_amd64/github.com/coreos/go-semver/semver.a: object is [linux amd64 go1.2.1 X:none] expected [linux amd64 go1.5.1 X:none]
# github.com/prometheus/common/expfmt
Godeps/_workspace/src/github.com/prometheus/common/expfmt/decode.go:23: import /home/nan/kubernetes/Godeps/_workspace/pkg/linux_amd64/github.com/prometheus/client_model/go.a: object is [linux amd64 go1.2.1 X:none] expected [linux amd64 go1.5.1 X:none]
# github.com/emicklei/go-restful
Godeps/_workspace/src/github.com/emicklei/go-restful/container.go:16: import /home/nan/kubernetes/Godeps/_workspace/pkg/linux_amd64/github.com/emicklei/go-restful/log.a: object is [linux amd64 go1.2.1 X:none] expected [linux amd64 go1.5.1 X:none]
!!! Error in /home/nan/kubernetes/hack/lib/golang.sh:376
  'CGO_ENABLED=0 go build -o "${outfile}" "${goflags[@]:+${goflags[@]}}" -ldflags "${goldflags}" "${binary}"' exited with status 2
Call stack:
  1: /home/nan/kubernetes/hack/lib/golang.sh:376 kube::golang::build_binaries_for_platform(...)
  2: /home/nan/kubernetes/hack/lib/golang.sh:535 kube::golang::build_binaries(...)
  3: hack/build-go.sh:26 main(...)
Exiting with status 1
!!! Error in /home/nan/kubernetes/hack/lib/golang.sh:456
  '( kube::golang::setup_env; local host_platform; host_platform=$(kube::golang::host_platform); local goflags goldflags; eval "goflags=(${KUBE_GOFLAGS:-})"; goldflags="${KUBE_GOLDFLAGS:-} $(kube::version::ldflags)"; local use_go_build; local -a targets=(); local arg; for arg in "$@";
do
    if [[ "${arg}" == "--use_go_build" ]]; then
        use_go_build=true;
    else
        if [[ "${arg}" == -* ]]; then
            goflags+=("${arg}");
        else
            targets+=("${arg}");
        fi;
    fi;
done; if [[ ${#targets[@]} -eq 0 ]]; then
    targets=("${KUBE_ALL_TARGETS[@]}");
fi; local -a platforms=("${KUBE_BUILD_PLATFORMS[@]:+${KUBE_BUILD_PLATFORMS[@]}}"); if [[ ${#platforms[@]} -eq 0 ]]; then
    platforms=("${host_platform}");
fi; local binaries; binaries=($(kube::golang::binaries_from_targets "${targets[@]}")); local parallel=false; if [[ ${#platforms[@]} -gt 1 ]]; then
    local gigs; gigs=$(kube::golang::get_physmem); if [[ ${gigs} -ge ${KUBE_PARALLEL_BUILD_MEMORY} ]]; then
        kube::log::status "Multiple platforms requested and available ${gigs}G &gt;= threshold ${KUBE_PARALLEL_BUILD_MEMORY}G, building platforms in parallel"; parallel=true;
    else
        kube::log::status "Multiple platforms requested, but available ${gigs}G &lt; threshold ${KUBE_PARALLEL_BUILD_MEMORY}G, building platforms in serial"; parallel=false;
    fi;
fi; if [[ "${parallel}" == "true" ]]; then
    kube::log::status "Building go targets for ${platforms[@]} in parallel (output will appear in a burst when complete):" "${targets[@]}"; local platform; for platform in "${platforms[@]}";
    do
        ( kube::golang::set_platform_envs "${platform}"; kube::log::status "${platform}: go build started"; kube::golang::build_binaries_for_platform ${platform} ${use_go_build:-}; kube::log::status "${platform}: go build finished" ) &amp;&gt; "/tmp//${platform//\//_}.build" &amp;
    done; local fails=0; for job in $(jobs -p);
    do
        wait ${job} || let "fails+=1";
    done; for platform in "${platforms[@]}";
    do
        cat "/tmp//${platform//\//_}.build";
    done; exit ${fails};
else
    for platform in "${platforms[@]}";
    do
        kube::log::status "Building go targets for ${platform}:" "${targets[@]}"; kube::golang::set_platform_envs "${platform}"; kube::golang::build_binaries_for_platform ${platform} ${use_go_build:-};
    done;
fi )' exited with status 1
Call stack:
  1: /home/nan/kubernetes/hack/lib/golang.sh:456 kube::golang::build_binaries(...)
  2: hack/build-go.sh:26 main(...)
Exiting with status 1
make: *** [all] Error 1
</code></pre>

<p>But the <code>go</code> in "<code>PATH</code>" is <code>1.5.1</code>:</p>

<pre><code>$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/local/go/bin
$ which go
/usr/local/go/bin/go
$ go version
go version go1.5.1 linux/amd64
</code></pre>

<p>So how can I fix this issue? </p>

<p>As explained in "<a href="https://askubuntu.com/a/151943/5470">How can you completely remove a package?</a>", a <code>sudo apt-get --purge autoremove</code> might have removed go completely.<br>
But that doesn't mean it has cleaned what was compiled before</p>

<p>Make sure that <code>/home/nan/kubernetes/Godeps/_workspace</code> and <code>/home/nan/kubernetes/_output</code> are deleted after a <strong><code>make clean</code></strong> (See <a href="https://github.com/kubernetes/kubernetes/issues/16771" rel="nofollow noreferrer">issue 16771</a>).<br>
Make sure <code>/usr/local/go/pkg</code> is writable for the user <code>nan</code>. (See <a href="https://github.com/kubernetes/kubernetes/blob/a5100ef05726237e4e1f44997852963c955b608c/hack/lib/golang.sh#L323-L325" rel="nofollow noreferrer"><code>hack/lib/golang.sh</code></a>)</p>

<p>Finally, <a href="https://github.com/kubernetes/kubernetes/issues/16229" rel="nofollow noreferrer">issue 16229</a> mentions:</p>

<blockquote>
  <p>Would be nice to at least update the docs to indicate that you can't use go>1.4.</p>
</blockquote>

<p>So try and <strong>install go 1.4.x only</strong>.</p>

<p>Update: the <a href="https://stackoverflow.com/users/2106207/nan-xiao">OP Nan Xiao</a> reports <a href="https://stackoverflow.com/questions/34080574/the-kubernetes-cant-find-correct-go-in-ubuntu/34081489#comment56305801_34081489">in the comments</a> having managed to build it with go 1.5.1 or 1.5.2 without any more issue.</p>
