My Golang project depends on a few packages (i.e. https://github.com/mattes/migrate and https://github.com/joho/godotenv). I know I can go get
or go install
them separately, but is there a way to install all of the dependencies of a project in one shot? Ideally, I would expect go install ./...
to put the migrate
and godotenv
binaries in my $GOPATH/bin
, but it only installs the main package binary and not the binaries of the dependencies.

如何安装依赖项的二进制文件?
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- dpiz9879 2016-04-12 11:48关注
Are you asking for a way to install the binaries you want to call, from your local machine, automatically from a
go install ./...
of your code?That isn't going to happen with straight up Go, unless they are listed in the same username or pattern you can type in a single go install command. But just the two listed above are different enough that that can't happen.
Option 1) Either state to your users to call
go install
for each Dependency (this is very common).Option 2) Or, create a bash/batch file to run them with a simple
install.sh
command in your repo. Which, would callgo install
for all of your dependencies. Another more UNIX/C like approach would be to create aMakefile
, and tell your users to runmake
Personally, I prefer option 2 as it gives you very complex control over your service or utility. You can start simple; but, later on add tests,
go generate
commands and whatever else you like in the future - all without having to change your installation instructionsjust run 'make install' and it will handle it
. It also helps with C.I. servers that you can have amake test
or anything to your hearts desire; but, different enough that normal users would usually run it. All, within a singleMakefile
that you can change later.I think my Updater script has like 25
go get -u -v
commands.本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报