After playing with the go
tool for a while, it looks like go get
:
a piece of software, while go install
simply
it. In this case, why does the go install
command exist, since go get
supersedes it?
Starting in Go 1.17, installing executables with go get is deprecated. go install may be used instead. In Go 1.18, go get will no longer build packages; it will only be used to add, update, or remove dependencies in go. mod . Specifically, go get will always act as if the -d flag were enabled.
Open the package file you downloaded and follow the prompts to install Go. The package installs the Go distribution to /usr/local/go. The package should put the /usr/local/go/bin directory in your PATH environment variable.
A go. mod file is required for the main module, and for any replacement module specified with a local file path. However, a module that lacks an explicit go. mod file may still be required as a dependency, or used as a replacement specified with a module path and version; see Compatibility with non-module repositories.
go install
is part of the workflow when working locally. Say you want to use a library, but for some reason a change is required. You would do:
go get -d library
, which only downloads it;go install library
to install the local version.As far as I know go get
has no flags to indicate it should not download, so it can't replace go install
here.
The same workflow is used when you develop a new package from scratch.
EDIT: 6 years later, Go 1.16 has updated and clarified the usage of go install
and go get
: https://tip.golang.org/doc/go1.16#modules
go get
does two main things in this order:
downloads and saves in $GOPATH/src/<import-path>
the packages (source code) named in the import paths, along with their dependencies, then
executes a go install
The -d
flag (go get -d
) instructs go get
to stop after downloading the packages; that is, it instructs go get
not to do go install
the difference:
go get
// verify if packages need to be downloaded, download if needed then compile
go install
// skip the part with packages download, just compile (this will throw an error if any packages are missing)
about GOPATH
environment variable
The GOPATH
environment variable is used by the Go tools. It must be set in order to be able to get
, build
and install
packages, and it specifies the location of your workspace. It is likely the only environment variable you'll need to set when developing Go code.
Again, the GOPATH
should not point to the Go installation, but rather to your workspace.
For example, on Windows, if you decide that your workspace is at c:\gowork\
, you will need to set GOPATH
value as c:\gowork
Your source code should be at c:\gowork\src\<some project folder>\
and after you run go get
at command prompt from within c:\gowork\src\<some project folder>\
you will see the c:\gowork\bin\
and c:\gowork\pkg\
being created.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With