Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wiki: SettingGOPATH (redesign) #34967

Closed
ghost opened this issue Oct 17, 2019 · 1 comment
Closed

wiki: SettingGOPATH (redesign) #34967

ghost opened this issue Oct 17, 2019 · 1 comment
Labels
Documentation FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@ghost
Copy link

ghost commented Oct 17, 2019

suggested to overwrite that page

Basic information on GOPATH is accessible by typing go help gopath.

$ go help gopath | head -7
The Go path is used to resolve import statements.
It is implemented by and documented in the go/build package.

The GOPATH environment variable lists places to look for Go code.
On Unix, the value is a colon-separated string.
On Windows, the value is a semicolon-separated string.
On Plan 9, the value is a list.
$ 

The value is unset, but a default is encoded in the go compiler.

($HOME/go on Unix, %USERPROFILE%\go on Windows, and $home/go on Plan 9)

login shells (Unix)

$ echo "export GOPATH=$HOME/go" >> ~/.profile
$
% echo "setenv GOPATH $HOME/go" >> ~/.login
%

interactive shells (Unix)

$ echo "export GOPATH=$HOME/go" >> ~/.bashrc
$
% echo "setenv GOPATH $HOME/go" >> ~/.cshrc
%

sourced files (Unix)

$ cat gopher
# GNU Bourne-Again SHell

export GOPATH=$HOME/go:/usr/share/gocode
$ . ~/gopher
$
% cat go-gopher
# Berkeley UNIX C shell

setenv GOPATH $HOME/go:/usr/share/gocode
% source ~/go-gopher
%

scripts (Windows)

C:\>TYPE gopher.bat
@ECHO OFF
SET GOPATH=%USERPROFILE%\go
C:\>
PS C:\> gc gopher.ps1
$env:GOPATH = "$HOME\go"
PS C:\> .\gopher.ps1
PS C:\>

sourced file (Plan 9)

% cat gopher
# Rc shell (usually a value of a single component)

GOPATH=$home/go
% . gopher
%

using GOENV (all)

$ go version
go version go1.13.3 linux/386
$ ed $GOROOT/src/os/file.go
17452
406,415p
// UserConfigDir returns the default root directory to use for user-specific
// configuration data. Users should create their own application-specific
// subdirectory within this one and use that.
//
// On Unix systems, it returns $XDG_CONFIG_HOME as specified by
// https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html if
// non-empty, else $HOME/.config.
// On Darwin, it returns $HOME/Library/Application Support.
// On Windows, it returns %AppData%.
// On Plan 9, it returns $home/lib.
q
$

NB: The root of the Go tree cannot be included as a value in the Go path.

@julieqiu
Copy link
Member

/cc @jayconrod

@julieqiu julieqiu added Documentation NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Oct 18, 2019
@ghost ghost closed this as completed Feb 9, 2020
@golang golang locked and limited conversation to collaborators Feb 8, 2021
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

2 participants