blob: 04942f538d5269279944c088192d43f8eff93441 [file] [log] [blame] [view]
Andrew Gerrand5bc444d2014-12-10 11:35:11 +11001(TODO: Add table of contents.)
2
3# Introduction
4
5There are many times in which you may install Go (either from source or from a binary distribution) and things don't work quite right. This page is meant to collect some common wisdom about problems that are relatively common or difficult to diagnose and provide tips and solutions.
6
7# Tips
8## Environment
9
10To start out with, check the following first:
11 * GOROOT
12 * This should _only_ be set if you used a binary distribution and it's not installed in the default location.
13 * [GOPATH](http://golang.org/cmd/go#GOPATH_environment_variable)
14 * This should be set to the directory under which you want your source (and third party packags).
15 * This can also be set to a list of absolute paths separated by : (or ; on Windows).
16 * Note that ~/some/path is not absolute and will probably not work the way you expect (try $HOME/some/path instead).
17 * GOPATH should not be set to or contain GOROOT
18 * GOBIN
19 * This should only be set if you _really_ know what you're doing... The default should be fine.
20 * GOOS, GOARCH, GOHOSTOS, GOHOSTARCH
21 * You shouldn't need to set these in normal cases.
22
23Under linux and darwin, make sure that any of the above variables which are set are actually exported. When you run the ` env | grep GO ` command, they should be listed. You can also check your environment with the ` go env ` command. In bash, this is done with the ` export GOPATH ` (if it's already set) or ` export GOPATH=/path/to/gopath ` command (similarly for the other variables), usually in your .bashrc or .bash\_profile.
24
25## GOROOT vs GOPATH
26Packages under GOROOT store their source files in
27
28` $GOROOT/src/pkg/import/path/*.go `
29
30Notice that this is ` src/pkg `; under GOPATH, source files are stored in
31
32` $GOPATH/src/import/path/*.go `
33
34Because of this inconsistency, it is generally not recommended that GOPATH be set to or contain GOROOT; its directories will be searched automatically for imports regardless of the GOPATH setting.
35
36# Troubleshooting
37## The ` go build ` command doesn't do anything!
38The ` go build ` command will only produce a binary; if you run go build in a package directory, it will build the package normally (and report any compile errors), but it will not install it. For that, you use ` go install `. If you think you're building a binary and none is produced, make sure you are in package ` main ` and that you do not have GOBIN set.
39
40## Why does ` go get ` report ` "Fetching https://runtime/cgo?go-get=1" `?
41If you have a source distribution, make sure that your packages are up-to-date. Also double check the environment above.
42
43## When cross compiling, I get ` "runtime/extern.go:135: undefined: theGoos" `
nathanybebb66f2014-12-10 22:44:37 -080044Read [[WindowsCrossCompiling]] for some helpful scripts. You can also use the ` --no-clean ` argument when you're building the cross-compile toolchain via ` make.bash `.
Andrew Gerrand5bc444d2014-12-10 11:35:11 +110045
46### Why does ` go get ` work for some packages and report ` permission denied ` in ` $GOROOT ` for some others (with GOPATH set properly)?
47If you at any point installed the package in ` GOROOT ` (either by having no ` GOPATH ` set or by including ` GOROOT ` itself in ` GOPATH `) then there might still be a directory in ` $GOROOT ` (which is always checked first) that is overriding your ` GOPATH `. To verify, run ` go list -f {{.Dir}} importpath ` and if it reports a directory under ` $GOPATH ` try deleting that first.
48
49## Still need help?
50Visit us on IRC or ask on the mailing list. You will want to provide the output of the following commands, in addition to any errors you are getting:
51```
52go version
53go env
54env | grep GO
55```