Go is printing xgcc version but not go installed version - go

On go version : It prints
go version xgcc (Ubuntu 4.9.1-0ubuntu1) 4.9.1 linux/amd64
My installed version is the latest one and i.e 1.4.2
which got installed from the tar version : go1.4.2.linux-amd64.tar.gz
GO Environmental variables looks exactly like this:
GOARCH="amd64"
GOBIN="/home/user/coding/golang/gocnew/goc/bin"
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/user/coding/golang/gocnew/goc"
GORACE=""
GOROOT="/home/user/go"
GOTOOLDIR="/home/user/go/pkg/tool/linux_amd64"
TERM="dumb"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
CXX="g++"
CGO_ENABLED="1"
I expect go version to be printed as 1.4.2, so how that can be achieved?

Looks like you have two versions of Go installed. One from ubuntu package manager and one you installed from source tar.
To confirm kindly try to remove gccgo :
sudo apt-get remove gccgo

I got the same issue and i fixed it by this way:
Access to go folder: /usr/local/go (The installation folder of go)
Execute these commands:
Added by Go Path
echo 'export GOROOT=/usr/local/go' >> ~/.bashrc
echo 'export GOPATH=$HOME/go' >> ~/.bashrc
echo 'export PATH=$PATH:$GOROOT/bin:$GOPATH/bin' >> ~/.bashrc
And then go to the source folder and check go version:
go version go1.12.2 linux/amd64 it will be displayed the same version in go folder and you can work with go commands.

Related

How to deal with "import cycle not allowed" while trying to install gonum?

I'd like to use the gonum libraries for go in order to experiment with some neural network stuff but I cannot go past the install process...
I'm running the command found on the official gonum website :
go get -u -t gonum.org/v1/gonum/...
But it gives me :
import cycle not allowed
package gonum.org/v1/gonum
imports runtime
imports internal/bytealg
imports internal/cpu
imports runtime
Do you know what could be a reason for such a problem?
In case you need my go env in order to help me out, here it is :
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/me/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
I'm running go 1.6.2.
As Adrian told in the comments, the issue was that the go version I was running was too old for gonum to install correctly. This was due to the fact that the go-golang package installed on my computer via apt-get was giving me the 1.6 version of go. By removing the package and making sure I had a recent go release installed on my computer I managed to install gonum.

Go tool unable to find binary. go tool: no such tool "vet"

I'm running golang in a docker container. And 'go tool' is unable to find 'vet'. Could you give me ideas on how to debug this?
I've used the Dockerfile for 1.5 as a template. https://github.com/docker-library/golang/blob/51d6eacd41fe80d41105142b9ad32f575082970f/1.5/Dockerfile
ENV GOLANG_VERSION 1.5.1
ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux- amd64.tar.gz
ENV GOLANG_DOWNLOAD_SHA1 46eecd290d8803887dec718c691cc243f2175fe0
RUN curl -fsSL "$GOLANG_DOWNLOAD_URL" -o golang.tar.gz \
&& echo "$GOLANG_DOWNLOAD_SHA1 golang.tar.gz" | sha1sum -c - \
&& tar -C /usr/local -xzf golang.tar.gz \
&& rm golang.tar.gz
ENV GOPATH /go
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
However, when I install govet with
go get golang.org/x/tools/cmd/vet
and try
bash-4.3# go tool vet
go tool: no such tool "vet"
I have the following go environment set up:
$PATH includes $GOPATH/bin /usr/lib/go/bin:/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
bash# go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/go"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT=""
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
bash# ls $GOPATH/bin
fgt go-junit-report godep golint mt-content-blogs vet
bash# ls $GOROOT/bin/
go gofmt
The crux of the issue is that go tools does not list vet, even after installing it with go get golang.org/x/tools/cmd/vet
bash# go tool
addr2line
api
asm
cgo
compile
dist
doc
fix
link
nm
objdump
pack
pprof
trace
yacc
Warning: starting Go 1.12 (February 2019, 3.5 years later), go tool vet won't be available at all. Only go vet.
See go 1.12 release notes:
The go vet command has been rewritten to serve as the base for a range of different source code analysis tools. See the golang.org/x/tools/go/analysis package for details.
A side-effect is that go tool vet is no longer supported.
External tools that use go tool vet must be changed to use go vet.
Using go vet instead of go tool vet should work with all supported versions of Go.
As part of this change, the experimental -shadow option is no longer available with go vet.
Checking for variable shadowing may now be done using:
go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
go vet -vettool=$(which shadow)
Figured out the issue. It appears that I had missed installing go tools on the base docker image that I was using.
RUN apk --update-cache --allow-untrusted \
--repository http://dl-3.alpinelinux.org/alpine/edge/community/ \
--arch=x86_64 add \
go=${GOLANG_VERSION}-r3 \
go-tools=${GOLANG_VERSION}-r3 \
git \
&& rm -rf /var/cache/apk/* \
&& mkdir -p /go/src /go/bin \
&& chmod -R 777 /go

Go lang installation issues with ./make.bash ubuntu->windows

I have tried to search and found a lot of topics which are related to my problem, but none of them I could follow to success.
I can go run and go get with no issues, but I need to compile into windows and there I have problems please see bellow
mikhail#mikhail-desktop:/usr/lib/go/src$ sudo ./make.bash
# Building C bootstrap tool.
cmd/dist
go tool dist: $GOROOT is not set correctly or not exported
GOROOT=/usr/share/go
/usr/share/go/include/u.h does not exist
mikhail#mikhail-desktop:/usr/lib/go/src$ go env
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/mikhail/Documents/FL/0go"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
TERM="dumb"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
CXX="g++"
CGO_ENABLED="1"
mikhail#mikhail-desktop:/usr/lib/go/src$
By some reasons it thinks the GOROOT is /usr/share/go while it actually /usr/lib/go
sudo can clean environment variables, to check if that is the case here, run sudo $(which go) env and check if the output is what you expect. If not, you can keep the enviroment of your user by using the -E flag: sudo -E ./make.bash.
I think it somehow connected to Debian/Ubuntu thing. I seen such issues but related to 0.9. version.
I have installed go from source into ~/go and then everything went quite OK, now I can compile to windows from ubuntu with help Introduction to cross compilation with go and LiteIDE.

go install: no install location for directory outside GOPATH

I installed the Go, then added path requirements to my .bash_profile:
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go
I then setup the correct folders:
I also created a projected called tire.
The contents for main.go are simply:
package main
import "fmt"
func main() {
fmt.Println("Hello, world!")
}
I always get the following error when I try to run go install:
go install: no install location for directory /Users/Daryl/go/src/tire outside GOPATH
Here's what I get when I run go env:
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/daryl/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
TERM="dumb"
CC="clang"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fno-common"
CXX="clang++"
CGO_ENABLED="1"
Any help would be appreciated.
When you run go install Go looks for $GOBIN env variable path. Either you need to set your $GOBIN to $GOPATH/bin
$ export GOBIN=$GOPATH/bin
and/or add $GOBIN to your OS search path
$ export PATH=$PATH:$GOBIN
To use the command without getting the error.
The problem was as James Henstridge commented, for some reason there was an issue with my user directory name case. Even though the directory is lowercase, I had to make it capitalized.
This worked:
GOPATH=/Users/Daryl/go
This didn't:
GOPATH=$HOME/go
However, since moving to a rMBP from my iMac, I had no problems whatsoever setting up Go, so, to this day, I'm not sure what was going on, but in that instance the capitalization fixed it.
I had the same problem in Windows 10,
So I set a system variable named GOBIN
with absolute value F:\go\bin.
Then ran go install main.go and everything worked perfectly fine!

Why is go install writing binary in the src directory?

I have a small go program in the directory:
~/gocode/src/github.com/elviejo79/goexample/
When I execute
go install
The program does compile but it leaves the executable in the same directory as the code.
but according to How to Write Go Code the binary should in fact be saved at
~/gocode/bin
this my $GOPATH
$ echo $GOPATH
/home/agarcia/gocode
Cannot reproduce this. Please Enter
$ go env
And verify where your GOBIN points to. For example, at the machine I'm right now, it says
09:01 myname#tux64:~$ go env
GOARCH="amd64"
GOBIN="/home/myname/bin"
GOCHAR="6"
GOEXE=""
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/myname"
GOROOT="/home/myname/go"
GOTOOLDIR="/home/myname/go/pkg/tool/linux_amd64"
CGO_ENABLED="1"
09:01 myname#tux64:~$
The go tool should send the binary to $GOBIN. Here it works like that.

Resources