Skip to content
Branch: master
Find file Copy path
Find file Copy path
1 contributor

Users who have contributed to this file

194 lines (133 sloc) 4.1 KB

Vendoring support

Go 1.5 introduced the concept of vendor. Go 1.11 (and modules) retains support for vendor. This is useful to ensure that all files used for a build are stored together in a single file tree. In addition, this allows interoperation with older versions of Go given older versions understand how to consume the vendor directory created by go mod vendor.

More information about the relationship between Go modules and vendor can be found in the vendoring FAQ on the wiki.

This example shows how to use go mod vendor to manage the vendor directory.


Create a module:

$ mkdir -p /home/gopher/scratchpad/hello
$ cd /home/gopher/scratchpad/hello
$ go mod init
go: creating new go.mod: module

Add a simple dependency to a main package in our module:

$ cat hello.go
package main

import (

func main() {

Run as a quick "test":

$ go run .
go: finding v1.5.2
go: downloading v1.5.2
go: extracting v1.5.2
go: finding v1.3.0
go: finding v0.0.0-20170915032832-14c0d48ead0c
go: downloading v1.3.0
go: extracting v1.3.0
go: downloading v0.0.0-20170915032832-14c0d48ead0c
go: extracting v0.0.0-20170915032832-14c0d48ead0c
Hello, world.

Review our dependencies:

$ go list -m all v0.0.0-20170915032832-14c0d48ead0c v1.5.2 v1.3.0

Vendor our dependencies:

$ go mod vendor

Review the contents of vendor:

$ cat vendor/modules.txt
# v0.0.0-20170915032832-14c0d48ead0c
# v1.5.2
# v1.3.0
$ find vendor -type d

Re-run our "test" using vendor:

$ go run -mod=vendor .
Hello, world.

For more information about the -mod flag see go help modules.

Version details

go version go1.12.5 linux/amd64
You can’t perform that action at this time.