英文:
Installing packages in a local directory
问题
安装包(使用go get...)到本地目录的最佳实践是什么?
例如:我想尝试一下Revel web框架,但我不想把它安装到/usr/local/go下。
通常我会在首页上写sudo go get github.com/robfig/revel,但这会将其安装到/usr/local/go/src/pkg/...下。
有没有一种简单的方法,比如说go get --local ...,可以将包安装到当前(子)目录下?
英文:
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 /usr/local/go.
Normally I'd say sudo go get github.com/robfig/revel as written on the home page, but that would install it beneath /usr/local/go/src/pkg/....
Is there an easy way to say (for example) go get --local ... and have the package in the current (sub) directory?
答案1
得分: 25
为了扩展keks的回答,你可以更新你的.bashrc文件,使其看起来像这样:
export GOROOT=/usr/local/go
export GOPATH=~/workspace/me/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
现在,使用go get安装的所有包都与go发行版分开。
英文:
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.
答案2
得分: 14
你可以导出环境变量GOPATH。对我来说,它是~/local/lib/go。这个文件夹有子文件夹bin、pkg和src,所以它就像/usr/local/go一样。go工具将自动下载、构建和安装包到这个目录中。
英文:
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.
答案3
得分: 10
你可能想考虑使用Go版本管理器(gvm)。
除了轻松切换Go版本外,它还可以让你在pkgsets(“工作区”)之间切换。
首先创建一个集合
gvm pkgset create myproject
然后使用它
gvm pkgset use myproject
非常好用。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论