Installing packages in a local directory

后端 未结 4 1169
野的像风
野的像风 2021-02-01 21:59

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\

相关标签:
4条回答
  • 2021-02-01 22:12

    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.

    0 讨论(0)
  • 2021-02-01 22:22

    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.

    0 讨论(0)
  • 2021-02-01 22:22

    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.

    0 讨论(0)
  • 2021-02-01 22:24

    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
    
    0 讨论(0)
提交回复
热议问题