github twitter linkedin telegram email
Handling Go dependencies with dep
Feb 13, 2018
2 minutes read


People coding in Golang is familiar with the ‘GOPATH’ the place where all your packages live. package management in go has been heavily opinionated and there has been many tools which attempted to solve this problem like glide,godep to name a few.

Now a tool called dep has been surfacing the go world for a while.Most go projects are now moving to dep.Let’s talk about using dep. It’s very simple to get started with dep.At root of your project, run this command

dep init

It takes a while to complete, because it is downloading all the project dependecies on to a directory called vendor in the directory where init was called.If you wanna see the progress instead of waiting at a blank promt append the previos command with a -v like,

dep init -v

Now you will have two new files in root directory

  1. Gopkg.toml
  2. Gopkg.lock

The first file is user editable and the second file is generated by dep, to know more about these files refer the official dep documentation here and here

Now dep is ready roll.From now on the only command you will probably need is

dep ensure

What this command essentialy do is update your dependecies. So how do you do that ?. Things are pretty simple, we do import our dependencies the same old way in our go source files, once we have done that do a dep ensure that’s it!.There’s no manual bookkeeping to be done, your Gopkg.toml will automatically be updated.

Now if you add a dependency more in the package manager way dep got you covered :)

dep ensure -add

To update dependecies run dep ensure -update <package name> rightaway

If you wanna update all dependencies run a dep ensure -update.

dep is an awesome tool and according to the official roadmap it will soon be added to the official golang toolchain.Refer the official dep docs for more.

Back to posts