To my knowledge go distribution
comes with some sort of package manager
. After go 1.4.1
installation I've run go help
in order to find any sub-command capable of listing locally installed go packages
, but unfortunately got none.
So how to do it?
To list packages in your workspace, go to your workspace folder and run this command: go list ./... ./ tells to start from the current folder, ... tells to go down recursively.
The packages from the standard library are available at the “pkg” subdirectory of the GOROOT directory. When you install Go, an environment variable GOROOT will be automatically added to your system for specifying the Go installer directory.
As we discussed, there are two types of packages. An executable package and a utility package.
Add the Go install directory to your system's shell path. That way, you'll be able to run your program's executable without specifying where the executable is. Once you've updated the shell path, run the go install command to compile and install the package. Run your application by simply typing its name.
goinstall
is now historygoinstall
was replaced by go get
. go get
is used to manage external / 3rd party libraries (e.g. to download them, update them, install them etc).
Type go help get
to see command line help, or check out these pages:
Command go
About the go command (blog post)
If you want to list installed packages, you can do that with the go list
command:
To list packages in your workspace, go to your workspace folder and run this command:
go list ./...
./
tells to start from the current folder, ...
tells to go down recursively. Of course this works in any other folders not just in your go workspace (but usually that is what you're interested in).
Executing
go list ...
in any folder lists all the packages, including packages of the standard library first followed by external libraries in your go workspace.
If you also want to see the imported packages by each package, you can try this custom format:
go list -f "{{.ImportPath}} {{.Imports}}" ./...
-f
specifies an alternate format for the list, using the syntax of package template
. The struct whose fields can be referenced can be printed by the go help list
command.
If you want to see all the dependencies recursively (dependencies of imported packages recursively), you can use this custom format:
go list -f "{{.ImportPath}} {{.Deps}}" ./...
But usually this is a long list and just the single imports ("{{.Imports}}"
) of each package is what you want.
Also see related question: What's the Go (mod) equivalent of npm-outdated?
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