Do you want BuboFlash to help you learning these things? Or do you want to add or correct something? Click here to log in or create user.



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
If you want to change selection, open document below and click on "Move attachment"

How to Write Go Code - The Go Programming Language
s must always use package main. Next, create a file named hello.go inside that directory containing the following Go code: package main import "fmt" func main() { fmt.Println("Hello, world.") } <span>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 Next, let's run the program to ensure it works. For added convenience, we'll add the install directory to our PATH to make running binaries easy: # Windows users should consult https://


Summary

statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

Details



Discussion

Do you want to join discussion? Click here to log in or create user.