Recently swapped to using Go 1.11 release and am trying to convert our projects over to using the new module system. However, I'm running into a frustrating issue with the caching system (I've thus far run with GOCACHE=off because of unrelated issues in the past, but that's not an option with modules).
The below command log is based on using a fresh upgrade of my system Go to 1.11 using Homebrew (I typically use gvm to install and manage Go versions, but swapped to system build for this to see if gvm was the issue). I set my GOPATH to a temporary directory and moved the source code out of the default GOPATH (it is currently at ~/gotemp/statsbot).
For this command log, I'm nuking the cache first, to get it in a fresh state. I'm then doing a build (to pull in any missing dependencies, which should also recache deps) followed by a test on one of the subdirectories.
[08:34:48] statsbot (feature/bot-rebuild-gomod) $ rm -rf on
[08:34:49] statsbot (feature/bot-rebuild-gomod) $ go clean --cache
[08:34:50] statsbot (feature/bot-rebuild-gomod) $ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="on"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/var/folders/ck/bf8_n8hn34j7bh7hqqppxrtm0000gn/T/tmp.3ga5Iq09"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.11/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.11/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/kaedys/gotemp/statsbot/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/ck/bf8_n8hn34j7bh7hqqppxrtm0000gn/T/go-build065167780=/tmp/go-build -gno-record-gcc-switches -fno-common"
[08:34:53] statsbot (feature/bot-rebuild-gomod) $ go build .
[08:35:01] statsbot (feature/bot-rebuild-gomod) $ ginkgo stats
Failed to compile stats:
# golang.org/x/text/runes
/var/folders/ck/bf8_n8hn34j7bh7hqqppxrtm0000gn/T/tmp.3ga5Iq09/pkg/mod/golang.org/x/text#v0.3.0/runes/cond.go:10:2: can't open import: "golang.org/x/text/transform": open on/51/51b9b2cf5a27a7ff06942814ad6ef031de64dc6d773c835916067578ea1ae3a1-d: no such file or directory
# golang.org/x/text/encoding
/var/folders/ck/bf8_n8hn34j7bh7hqqppxrtm0000gn/T/tmp.3ga5Iq09/pkg/mod/golang.org/x/text#v0.3.0/encoding/encoding.go:19:2: can't open import: "golang.org/x/text/encoding/internal/identifier": open on/4c/4c2fad64312f6ec34b38755ccecb96bb31c6995211f39e0eb4112abc2fac560c-d: no such file or directory
# gopkg.in/fsnotify.v1
/var/folders/ck/bf8_n8hn34j7bh7hqqppxrtm0000gn/T/tmp.3ga5Iq09/pkg/mod/gopkg.in/fsnotify.v1#v1.4.7/kqueue.go:18:2: can't open import: "golang.org/x/sys/unix": open on/77/77790588f9aed90a52efdb1dac069953e1ea2bf82db8627a47a9492862b39c6e-d: no such file or directory
Ginkgo ran 1 suite in 4.123499564s
Test Suite Failed
I see this same error message in a number of build situations. go build . will usually succeed, but sometimes will fail with similar messages. Running go clean --cache invariable fixes these issue, but I don't really want to run that before every build, and it doesn't work when trying to use Ginkgo to test since that seems to involve several successive compilations.
The error itself is what's baffling, because these files do exist:
[08:40:49] statsbot (feature/bot-rebuild-gomod) $ ll on/4c
total 112
-rw-r--r-- 1 kaedys staff 18346 Sep 14 08:40:19 2018 4c1d5db302dff0381c402160d7fd2bd89a6dafd3edc61b3dbd5e8f1a85108fb7-d
-rw-r--r-- 1 kaedys staff 27980 Sep 14 08:40:45 2018 4c2fad64312f6ec34b38755ccecb96bb31c6995211f39e0eb4112abc2fac560c-d
-rw-r--r-- 1 kaedys staff 175 Sep 14 08:40:20 2018 4cbbc40c46eba0ef41f3ebd23470c3327215fa6e05e269c276c6635da79f2e8e-a
-rw-r--r-- 1 kaedys staff 13 Sep 14 08:40:20 2018 4cffcbd4a7f1255ca3696f5e24e0b1045d14c25f1f90cbbb077b5d6f2d11e68c-d
The second file in that ll is the file the second error message complained was missing, so I can only assume that either it was trying to access the file while the file was still being generated, or it was looking in a different directory (which is difficult to tell, since the error message only reports a relative path for the file).
Posting here to see if anyone knows how to solve this or if it's something funky in my environment setup before creating an official issue on the Go github.
Your GOCACHE environment variable is set to "on". Value of GOCACHE must be a folder, and the special "off" value means to not cache build and test results and to not use already cached data of those. There is no special value "on".
You don't have to set GOCACHE, as it has a default value. Quoting from Command Go: Build and test caching:
The go command caches build outputs for reuse in future builds. The default location for cache data is a subdirectory named go-build in the standard user cache directory for the current operating system. Setting the GOCACHE environment variable overrides this default, and running 'go env GOCACHE' prints the current cache directory. You can set the variable to 'off' to disable the cache.
Related
I installed go tools in vscode and the terminal showed that the tools are installed successfully:
Tools environment: GOPATH=/home/spindrift/go
Installing 1 tool at /home/spindrift/go/bin in module mode.
gopls
Installing golang.org/x/tools/gopls (gopls) SUCCEEDED
All tools successfully installed. You are ready to Go :).
But after installing the vscode keep showing gopls is inquired but missing
So I take a look at $GOPATH/bin, and there's only dlv-dap in it!
I check my configured tools:
Checking configured tools....
GOBIN: undefined
toolsGopath:
gopath: /home/spindrift/go
GOROOT: /usr/local/go
PATH: /usr/local/go/bin:/home/spindrift/.vscode-server/bin/ea3859d4ba2f3e577a159bc91e3074c5d85c0523/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Program Files/WindowsApps/Microsoft.WindowsTerminal_1.12.10732.0_x64__8wekyb3d8bbwe:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/DevelopTools/Maven/apache-maven-3.2.5/bin:/mnt/c/DevelopTools/mingw64/mingw64/bin:/mnt/c/DevelopTools/Matlab2018a/runtime/win64:/mnt/c/DevelopTools/Matlab2018a/bin:/mnt/c/DevelopTools/Lingo/:/mnt/c/DevelopTools/MongoDB/Server/bin:/mnt/c/DevelopTools/Git/cmd:/mnt/c/DevelopTools/mysql/bin:/mnt/c/DevelopTools/anaconda3:/mnt/c/DevelopTools/anaconda3/Scripts:/mnt/c/DevelopTools/anaconda3/Library/bin:/mnt/c/WINDOWS/system32:/mnt/c/DevelopTools/Go/bin:/mnt/c/DevelopTools/scala/bin:/mnt/c/Program Files/dotnet/:/mnt/c/Users/Libra/AppData/Local/Microsoft/WindowsApps:/mnt/c/DevelopTools/VSCode/Microsoft VS Code/bin:/mnt/c/Software/Bandizip/:/mnt/c/Users/Libra/AppData/Roaming/npm:/mnt/c/DevelopTools/nodejs:/mnt/c/Users/Libra/go/bin:/mnt/c/Users/Libra/.dotnet/tools:/snap/bin
PATH (vscode launched with): /home/spindrift/.vscode-server/bin/ea3859d4ba2f3e577a159bc91e3074c5d85c0523/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Program Files/WindowsApps/Microsoft.WindowsTerminal_1.12.10732.0_x64__8wekyb3d8bbwe:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/DevelopTools/Maven/apache-maven-3.2.5/bin:/mnt/c/DevelopTools/mingw64/mingw64/bin:/mnt/c/DevelopTools/Matlab2018a/runtime/win64:/mnt/c/DevelopTools/Matlab2018a/bin:/mnt/c/DevelopTools/Lingo/:/mnt/c/DevelopTools/MongoDB/Server/bin:/mnt/c/DevelopTools/Git/cmd:/mnt/c/DevelopTools/mysql/bin:/mnt/c/DevelopTools/anaconda3:/mnt/c/DevelopTools/anaconda3/Scripts:/mnt/c/DevelopTools/anaconda3/Library/bin:/mnt/c/WINDOWS/system32:/mnt/c/DevelopTools/Go/bin:/mnt/c/DevelopTools/scala/bin:/mnt/c/Program Files/dotnet/:/mnt/c/Users/Libra/AppData/Local/Microsoft/WindowsApps:/mnt/c/DevelopTools/VSCode/Microsoft VS Code/bin:/mnt/c/Software/Bandizip/:/mnt/c/Users/Libra/AppData/Roaming/npm:/mnt/c/DevelopTools/nodejs:/mnt/c/Users/Libra/go/bin:/mnt/c/Users/Libra/.dotnet/tools:/snap/bin:/usr/local/go/bin
go: /usr/local/go/bin/go: go version go1.18.1 linux/amd64
gopkgs: not installed
go-outline: not installed
gotests: not installed
gomodifytags: not installed
impl: not installed
goplay: not installed
dlv: not installed
dlv-dap: /home/spindrift/go/bin/dlv-dap: go1.18.1
path github.com/go-delve/delve/cmd/dlv
mod github.com/go-delve/delve v1.8.3-0.20220413222856-313815782614 h1:J92Zq5+vc+zzd0Gn69RxVUUC3orKgciGmurMPUSci4I=
dep github.com/cilium/ebpf v0.7.0 h1:1k/q3ATgxSXRdrmPfH8d7YK0GfqVsEKZAX9dQZvs56k=
dep github.com/cosiner/argv v0.1.0 h1:BVDiEL32lwHukgJKP87btEPenzrrHUjajs/8yzaqcXg=
dep github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM=
dep github.com/derekparker/trie v0.0.0-20200317170641-1fdf38b7b0e9 h1:G765iDCq7bP5opdrPkXk+4V3yfkgV9iGFuheWZ/X/zY=
dep github.com/go-delve/liner v1.2.2-1 h1:0hGpZh6vjI6LFTlXuHFCX9PebaluzDzps2owdMrrSuk=
dep github.com/google/go-dap v0.6.0 h1:Y1RHGUtv3R8y6sXq2dtGRMYrFB2hSqyFVws7jucrzX4=
dep github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
dep github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI=
dep github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
dep github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
dep github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
dep github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
dep github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
dep github.com/spf13/cobra v1.1.3 h1:xghbfqPkxzxP3C/f3n5DdpAbdKLj4ZE4BWQI362l53M=
dep github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
dep go.starlark.net v0.0.0-20200821142938-949cc6f4b097 h1:YiRMXXgG+Pg26t1fjq+iAjaauKWMC9cmGFrtOEuwDDg=
dep golang.org/x/arch v0.0.0-20190927153633-4e8777c89be4 h1:QlVATYS7JBoZMVaf+cNjb90WD/beKVHnIxFKT4QaHVI=
dep golang.org/x/sys v0.0.0-20211117180635-dee7805ff2e1 h1:kwrAHlwJ0DUBZwQ238v+Uod/3eZ8B2K5rYsUHBQvzmI=
dep gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
build -compiler=gc
build CGO_ENABLED=1
build CGO_CFLAGS=
build CGO_CPPFLAGS=
build CGO_CXXFLAGS=
build CGO_LDFLAGS=
build GOARCH=amd64
build GOOS=linux
build GOAMD64=v1
staticcheck: not installed
gopls: not installed
It seems that I failed to install go tools. I tried several times but the problem still unsolved.
Here's my go env
GO111MODULE="auto"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/spindrift/.cache/go-build"
GOENV="/home/spindrift/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/spindrift/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/spindrift/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18.1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1163911802=/tmp/go-build -gno-record-gcc-switches"
This is a bug in the go extension which occurs when using go 1.18. It has been fixed in recent versions of vscode-go, for details see [1] and [2].
Updating vscode and the go extension (vscode-go) should resolve your problem (as it did for me).
[1] https://github.com/golang/vscode-go/issues/2143
[2] https://github.com/golang/vscode-go/commit/656865daa974f43e8e88310e5076f3f0c4936c73
GOBIN is not present in your $PATH.
the easiest way is to add one more line to your .bashrc / .zshrc in $HOME
PATH = $PATH:$HOME
learn more on $PATH here
Some configurations are fetched from "GOENV" file.
Make sure params in that file are valid, Especially look for "GOROOT" in it.
It should exactly match your GO executable path. (In most cases it could be /usr/local/go)
If not valid, update values and try again.
The gopls is present in GOPATH and GOROOT, but still VS Code complains about not being able to find gopls.
Configured tools output shows gopls and other tools properly installed.
go version 1.17.12
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.
I tried to install Revel Framework. I followed all the steps as given in the documentation but whenever I tried to run the Revel command it throws panic error.
Following are the steps which I am performing
Enviormental path:
export GOROOT=/usr/local/go
export GOPATH=/Users/<username>/Desktop/gocode
export PATH="/Users/<username>/gocode/bin:$PATH"
To install Revel
go get github.com/revel/revel
go get github.com/revel/cmd/revel
export PATH="$PATH:$GOPATH/bin"
when I run revel version it shows:
panic: runtime error: slice bounds out of range
goroutine 1 [running]:
github.com/revel/cmd/model.(*CommandConfig).UpdateImportPath(0xc4200961c0, 0x20)
/Users/amitsharma/Desktop/gocode/src/github.com/revel/cmd/model/command_config.go:122 +0x907
main.main()
/Users/amitsharma/Desktop/gocode/src/github.com/revel/cmd/revel/revel.go:133 +0x243
When I run
revel run -a my-app
It shows
ERROR 19:34:59 harness.go:231: Could not start application error="revel/harness: app died reason: exit status 2"
INFO 19:34:59 watcher.go:272: Watcher: Recording error last build, setting rebuild on error="App failed to start up: revel/harness: app died reason: exit status 2"
INFO 19:34:59 watcher.go:277: Rebuilt, result error="App failed to start up: revel/harness: app died reason: exit status 2"
My go version
go version go1.10.3 darwin/amd64
My go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/amitsharma/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/<username>/Desktop/gocode"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/0d/pkfrs5cj0v57xgsnwvb2kb580000gn/T/go-build028697826=/tmp/go-build -gno-record-gcc-switches -fno-common"
Try re-install the revel
Here is how I have tried and it works for me.
Set the go path ($GOPATH):
export GOPATH=/var/projects/go
Install revel & cmd:
go get github.com/revel/revel
go get github.com/revel/cmd/revel
Link revel cmd to bin directory. So the command could be executable.
export PATH="$PATH:$GOPATH/bin
Check revel is working or not. Just type revel in command line
Output would be like this
Usage:
revel [OPTIONS] <command>
Application Options:
-v, --debug If set the logger is set to verbose
--historic-run-mode If set the runmode is passed a string not json
-X, --build-flags= These flags will be used when building the application. May be specified multiple times, only applicable for Build, Run,
Package, Test commands
Available commands:
build
clean
new
package
run
test
version
Check revel version:
revel version
Output
Revel executing: displays the Revel Framework and Go version
Revel Framework : 0.21.0 (0.21.0 remote master branch)
Revel Cmd : 0.21.1 (0.21.1 remote master branch)
Revel Modules : 0.21.0 (0.21.0 remote master branch)
Now, You can create first project using command
revel new myapp
Output
Revel executing: create a skeleton Revel application
Your application has been created in:
/var/projects/go/src/myapp
You can run it with:
revel run -a myapp
This is not a repeat of this question:
what should be the values of GOPATH and GOROOT?
I don't want to know what the values should be. I want to know what I should see when I type ls $GOROOT or ls $GOPATH into console. I'm pretty sure I set things up wrong following a tutorial almost a year ago, and I want to be able to confirm that these two are pointing to where they should be by simply checking that what they point to looks right.
Here's where I am right now. It looks like $GOROOT is pointing nowhere. I'm pretty sure it should be pointing at usr/local/go, but it would be a lot easier to confirm if I knew what the expected result of ls $GOROOT is supposed to be.
As for $GOPATH I'm not totally sure if my "workspace" is where all my go code is, or maybe just the github stuff, or maybe the particular folder I'm working within. I know it's supposed to point to my "work space," but I don't know what that work space I'm looking for looks like.
Sephs-MBP:ThumbzArt seph$ $GOROOT
Sephs-MBP:ThumbzArt seph$ $GOPATH
-bash: /Users/seph/code/golang: is a directory
Sephs-MBP:ThumbzArt seph$ ls $GOROOT
Bman.jpg README.md ThumbzArt.sublime-workspacescripts thumbzart.go
LICENSE.md ThumbzArt.sublime-project public templates ticktock.go
Sephs-MBP:ThumbzArt seph$ $GOPATH
-bash: /Users/seph/code/golang: is a directory
Sephs-MBP:ThumbzArt seph$ ls $GOPATH
- bin p pkg src
Sephs-MBP:ThumbzArt seph$ ls /usr/local/go
AUTHORS CONTRIBUTORS PATENTS VERSION bin doc lib pkg src
CONTRIBUTING.md LICENSE README.md api blog favicon.ico misc robots.txt test
Sephs-MBP:ThumbzArt seph$
I know this question seems ridiculous, but it's hard to confirm things for which you have no expected results.
Thank you
Sephs-MBP:streak seph$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/seph/code/golang"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT=""
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"
Sephs-MBP:streak seph$ go version
go version go1.5.2 darwin/amd64
Sephs-MBP:streak seph$ which go
/usr/local/go/bin/go
EDIT: Another very useful feature I just stumbled across is this: go help gopath. This should have probably been somebodies answer.
The folder $GOPATH points to should like this:
Sephs-MBP:streak seph$ ls $GOPATH
- bin p pkg src
$GOROOT, on the other hand, will yield unexpected results if you use ls $GOROOT as compared to ls $GOPATH. This is because $GOROOT is not set within this context, I think.
Sephs-MBP:helloworld seph$ ls $GOROOT
helloworld.go
If you use go env you'll see the true nature of $GOROOT
Sephs-MBP:streak seph$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/seph/code/golang"
GORACE=""
GOROOT="/usr/local/go" //this is where it actually points
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT=""
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused- arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"
And if you get the result of $GOROOT from go env and do ls you should see something like this:
Sephs-MBP:streak seph$ ls /usr/local/go
AUTHORS CONTRIBUTORS PATENTS VERSION bin doc lib pkg src
CONTRIBUTING.md LICENSE README.md api blog favicon.ico misc robots.txt test
If all of these things check out, then your $GOPATH and $GOROOT are properly set.
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.