在本地目录中安装软件包

huangapple go评论88阅读模式
英文:

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。这个文件夹有子文件夹binpkgsrc,所以它就像/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.

huangapple
  • 本文由 发表于 2012年9月20日 21:47:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/12514037.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定