Now you can build and install that program with the go
tool:
$ go install example/user/hello $
This command builds the hello
command, producing an executable
binary. It then installs that binary as $HOME/go/bin/hello
(or,
under Windows, %USERPROFILE%\go\bin\hello.exe
).
The install directory is controlled by the GOPATH
and GOBIN
environment
variables. If GOBIN
is set, binaries are installed to that
directory. If GOPATH
is set, binaries are installed to
the bin
subdirectory of the first directory in
the GOPATH
list. Otherwise, binaries are installed to
the bin
subdirectory of the default GOPATH
($HOME/go
or %USERPROFILE%\go
).
You can use the go env
command to portably set the default value
for an environment variable for future go
commands:
$ go env -w GOBIN=/somewhere/else/bin $
To unset a variable previously set by go env -w
, use go env -u
:
$ go env -u GOBIN $
Commands like go install
apply within the context of the module
containing the current working directory. If the working directory is not within
the example/user/hello
module, go install
may fail.
For convenience, go
commands accept paths relative
to the working directory, and default to the package in the
current working directory if no other path is given.
So in our working directory, the following commands are all equivalent:
$ go install example/user/hello
$ go install .
$ go install
status | not read | reprioritisations | ||
---|---|---|---|---|
last reprioritisation on | suggested re-reading day | |||
started reading on | finished reading on |