dep is a dependency management tool for golang. If you have done any software development before,
dep is similar to
pip. In simple words, it is a package manager to manage
your project’s third party libraries.
1$~ brew install dep
To initialize it in your
go project, go to your project directory and run the following
1$~ dep init
This will create three things in your directory
Gopkg.toml: This where you specifies the project dependencies
Gopkg.lock: File generated as a result from running
dep. It’s a complete dependency graph for your project. You shouldn’t edit this manually.
vendor/: This is where the dependencies are stored
dep init will behave differently depending on the state of your project.
If it is a new project,
vendor/ will be essentially empty aside
from the usual commented out guides on how to use it.
If it is an existing project,
vendor/ will add all the dependencies
that you have added in your project with
To add a new depencies in your project, run the following
1$~ dep ensure -add <DEPENDENCIES>
<DEPENDENCIES> with the path to its project repo. For example
1$~ dep ensure -add github.com/gorilla/mux
A few more commands that I find useful:
dep status: Will report the status of your project dependencies
dep prune: Will tell you which libraries that are out of sync
I am sure by now you are asking “why should I use
go dep when go already comes with
Well, imagine you are working in a team project that uses a lot of dependencies. Each having their own version of libraries. Pretty soon you will have those “Works on my machine!” real quick.
dep solve this by making sure everyone who works on the project is guaranteed to be
using the same version of dependencies.
That’s it. Hopefully now you have learned the basic usage sof
go dep to manage your project dependencies.