134

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 7

272

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.

6
  • 1
    If i need to run/ modify the code then it doesn't find packages.
    – user5370520
    Sep 24, 2015 at 9:49
  • 1
    I know i can get packages by go get <package> but it is so much time consuming and difficult when the program uses many packages.
    – user5370520
    Sep 24, 2015 at 9:51
  • 7
    -t will install also test dependencies
    – honzajde
    Apr 19, 2017 at 12:47
  • 4
    @AlbertoSchiabel ... is a special pattern. It tells to go down recursively. I've updated an answer
    – RoninDev
    May 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
60

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.

0
53

Below command works for me it downloads all the dependencies.

go get -u -v -f all
1
  • 2
    it takes a long time !!! it downloads packages that I never used in the project!
    – Yuseferi
    Oct 4, 2020 at 15:48
17

It's go mod download. For more info check go help mod

10

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.

1
  • 12
    Maybe 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
    – Patratacus
    Nov 25, 2018 at 3:41
8

If you are using module mode, you can try go mod tidy, as described here.

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.