How to get all dependency files for a program

Go

Go 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" }}')

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser5370520View Question on Stackoverflow
Solution 1 - GoRoninDevView Answer on Stackoverflow
Solution 2 - GofiatjafView Answer on Stackoverflow
Solution 3 - GoinfiniteLearnerView Answer on Stackoverflow
Solution 4 - GoAnimesh Kumar PaulView Answer on Stackoverflow
Solution 5 - GoMathObsessedView Answer on Stackoverflow
Solution 6 - GoKaonashi HirotaView Answer on Stackoverflow
Solution 7 - GoDarlan DieterichView Answer on Stackoverflow