You can export the env variable
GOPATH. For me it is
~/local/lib/go. This folder has the subfolders
src, so it's just like
go-tool will then automatically download , build and install packages into this directory.
What is the best practice to install packages (those with
go get...) in a local directory?
Example: I'd like to try out the Revel web framework, but I don't want to clutter my go installation at
Normally I'd say
sudo go get github.com/robfig/revel as written on the home page, but that would install it beneath
Is there an easy way to say (for example)
go get --local ... and have the package in the current (sub) directory?
4条回答 默认 最新
- 已采纳 douji5523 2012-09-20 13:55
You can export the env variable点赞 评论 复制链接分享
- dongzi8191 2012-09-20 14:15
To expand on keks answer, you can update your .bashrc to look like this
export GOROOT=/usr/local/go export GOPATH=~/workspace/me/go export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
Now all packages installed with
go getare separate from the go distribution.点赞 评论 复制链接分享
- doqdcks3948 2013-07-12 14:17
You might want to consider using Go Version Manager (gvm).
Apart from switching between Go versions easily, it also lets you switch between pkgsets ("workspaces").
First you create a set
gvm pkgset create myproject
and then you use it
gvm pkgset use myproject
Works like a charm.点赞 评论 复制链接分享
- doukucai0099 2019-01-24 17:07
In modern module enabled go (introduced in go 1.11), you can use the gobin program with a GOBIN env var specifying the destination of the binary:
GOBIN=./local gobin github.com/robfig/revel
Installation of gobin is done like so:
GO111MODULE=off go get -u github.com/myitcv/gobin点赞 评论 复制链接分享