How to get all dependency files for a program
GoGo Problem Overview
I make a program in Go and after completing the code, if I want to run this code on other pc or VM, then it does not get all the dependency package files. How can I get all dependency files?
Go Solutions
Solution 1 - Go
You can run go get -d ./...
from a directory of your project to download all go-gettable dependencies.
Or copy all src
subdirectory from your GOPATH to the destination machine.
...
is a special pattern, tells to go down recursively.
Solution 2 - Go
Try
go list -f '{{ join .Imports "\n" }}'
or
go list -f '{{ join .Deps "\n" }}'
The second will list all subdependencies, the first only the directly imported packages.
Solution 3 - Go
Below command works for me it downloads all the dependencies.
go get -u -v -f all
Solution 4 - Go
You can use godep save
in your local pc where you complete your program. godep save collect all the dependency files for you. When you move to other pc, just copy the Godep folder with your code and it will solve your problems.
Solution 5 - Go
It's go mod download
. For more info check go help mod
Solution 6 - Go
If you are using module mode, you can try go mod tidy
, as described here.
Solution 7 - Go
Best way ever is get the list and iterate installing the packages, this works so fine:
while read l; do go get -v "$l"; done < <(go list -f '{{ join .Imports "\n" }}')