-2

I cloned a project from Github and before starting to work I have to install all the dependencies listed in the go.mod file.

I can do it one my one using the go get command, but is there any other alternative to this. Something like npm i and it installs the required dependencies all at once.

Or maybe I am getting something wrong here.

Om Gupta
  • 192
  • 2
  • 8

3 Answers3

4

The go command automatically downloads dependencies as needed.

Execute the command go mod download in the directory containing go.mod to ensure that all of the module dependencies are downloaded to the local module cache.

See the go mod download documentation for more details.

2

Usually there is no need to download packages manually that are listed in go.mod file. go command can automatically download all direct and transitive dependencies of the project in the module cache and then use those downloaded packages while building the project.

npm works differently since it downloads all direct and transitive dependencies of a project into a node_modules directory local to the project.

If you want npm like package management in Go, the closest you can get is with the Vendoring feature of Go.

go mod vendor command creates a directory named vendor in the root of main module containing all the packages that are necessary to support the builds and tests of the packages in the main module.

More detailed information about Vendoring is available in official Go docs.

cod3rboy
  • 717
  • 7
  • 9
0

You can try it the command

go list
l0s7r
  • 25
  • 9