go

Installing all dependencies from a go.mod file


What is the golang command that is equivalent to npm install

npm install downloads all the dependencies listed in the package.json file.

Having said that, what is the command that downloads all the dependencies in the go.mod file?


Solution

  • If you have only a go.mod and you have Go 1.16 or later:

    Both the above will create a go.sum file (this is maintained by the Go Tools - you can ignore it, but do check it into version control)

    The vendor command will create a vendor folder with a copy of all the source code from your dependencies. Note: If you do use the vendor approach, you will need to run go mod vendor if there is a change in your dependencies, so that a copy is downloaded to the vendor folder. The advantage is your code will build without an internet connection. The disadvantage is you need to keep it up to date.

    That should get you started for every day use.

    If you'd like to know all about modules, this is a good source.