SoFunction
Updated on 2025-03-05

How to configure golang development environment using dep

summary

Golang's package management has never had an official unified solution, so many unofficial package management tools have been produced. The gb (/) I used before can well separate the golang projects. At that time, the projects created by gb were not very integrated into the existing GOPATH. gb is equivalent to taking the project directory as GOPATH, and its vendor directory is also different from golang's own vendor.

The Roadmap of dep has already been formulated to become the official golang package management tool, so using dep to organize your own golang projects can better combine with other golang projects in the future.

Configuration

Golang configuration

My golang configuration is mainly divided into 3 blocks:

•GOROOT: Used to store golang itself. When updating golang version, just update this
•GOPATH: Tools for storing golang (gofmt, gocode, etc.)
•GOPROJECTS: used to store various golang projects

export GOROOT=/usr/local/go
export GOPROJECTS=/path/to/goprojects
export GOPATH=/path/to/gopath
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin:$GOPROJECTS/bin

export GOPATH=$GOPATH:$GOPROJECTS

Go project configuration

Create your own golang project under $GOPROJECTS/src

cd $GOPROJECTS/src
mkdir myGolangProject
cd myGolangProject

touch 
# write some golang code in 

dep init
dep ensure # add dependencies for 

go install # compile myGolangProject

myGolangProject can be submitted as a git repository to a remote git repository for easy sharing with others

Summarize

In fact, many golang's package management tools are good, and they don't even need package management tools. The purpose of golang project management can be achieved by reasonably dividing GOPATH. Using dep is, on the one hand, because it is likely to become the official package management tool of golang in the future, and on the other hand, it is also to better share golang code. After all, through dep, others can install all dependencies with one click to avoid writing many installation instructions documents.

The above operation method for configuring the golang development environment using dep is all the content I share with you. I hope you can give you a reference and I hope you can support me more.