Go Tools — go get

Download dependency.

김영석
2 min readAug 29, 2022

Continuing from the previous article about Go Tools — env, fmt, imports,

Today, I would like to write about “go get” which is the most frequently used one for dependency management.

the command is executed in the form of

$ go get <package@version>

This command lets you install the desired dependency with the specific version. Otherwise, you can simply add a suffix like @latest to fetch the latest version, or @none to uninstall the dependency.

For example, let’s say you have a clean directory with zero dependencies in $GOPATH/pkg/mod directory.

in unix system, that’d be $HOME/go/pkg/mod

→ /Users/yeongseokkim/go/pkg/mod

Confirming that there are no files or directories before doing download test

(to clean up, you can do it by $ go clean -modcache )

➜ mod tree .
.
0 directories, 0 files

and then execute the following command to download a module with a specific version in a Go application project .

➜ go-app-one git:(main) go get github.com/youngstone89/go-module-one@v0.1.1
go: downloading github.com/youngstone89/go-module-one v0.1.1

Once the download is completed, you can see changes in the $GOPATH/pkg/mod directory like this

➜  mod tree .
.
├── cache
│ └── download
│ └── github.com
│ └── youngstone89
│ └── go-module-one
│ └── @v
│ ├── list
│ ├── v0.1.1.info
│ ├── v0.1.1.lock
│ ├── v0.1.1.mod
│ ├── v0.1.1.zip
│ └── v0.1.1.ziphash
└── github.com
└── youngstone89
└── go-module-one@v0.1.1
├── README.md
├── go.mod
└── pkg
└── kafka
└── consumer.go

cache directory and github.com got newly created to store the downloaded dependency.

Now you are ready to import the downloaded dependency and implement.

This is how go get works.

Thanks!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

김영석
김영석

Written by 김영석

I love problem solving and hate repetition of tedious tasks. I like automating, streamlining, optimizing, things.

No responses yet