Installing packages in a local directory

不羁岁月 提交于 2019-12-02 22:09:39

You can export the env variable GOPATH. For me it is ~/local/lib/go. This folder has the subfolders bin, pkg and src, so it's just like /usr/local/go. The go-tool will then automatically download , build and install packages into this directory.

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 get are separate from the go distribution.

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.

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!