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?
7 Answers
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.
-
1If i need to run/ modify the code then it doesn't find packages.– user5370520Sep 24, 2015 at 9:49
-
1I know i can get packages by go get <package> but it is so much time consuming and difficult when the program uses many packages.– user5370520Sep 24, 2015 at 9:51
-
7
-
4@AlbertoSchiabel
...
is a special pattern. It tells to go down recursively. I've updated an answer– RoninDevMay 11, 2017 at 13:21 -
Thanks @RoninDev! At first I was going to edit your answer to
./.
, because after having tried you command on my pc it kind of stuck (and now I know why, since recursive search of go files can be quite expensive), but then I realized it was better to ask first. Thanks! May 11, 2017 at 13:29
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.
Below command works for me it downloads all the dependencies.
go get -u -v -f all
-
2it takes a long time !!! it downloads packages that I never used in the project!– YuseferiOct 4, 2020 at 15:48
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.
-
12Maybe it's obvious to some people, but I had to go dig this up. Turns out you need to install the godep or dep package to Go. The Github stie for this is here: github.com/tools/godep Nov 25, 2018 at 3:41
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" }}')