How can I install a package with go get?

前端 未结 2 1819
说谎
说谎 2021-01-29 19:24

I want to install packages from github to my gopath, I have tried this:

go get github.com:capotej/groupcache-db-experiment.git

the repository i

2条回答
  •  一整个雨季
    2021-01-29 19:45

    First, we need GOPATH

    The $GOPATH is a folder (or set of folders) specified by its environment variable. We must notice that this is not the $GOROOT directory where Go is installed.

    export GOPATH=$HOME/gocode
    export PATH=$PATH:$GOPATH/bin
    

    We used ~/gocode path in our computer to store the source of our application and its dependencies. The GOPATH directory will also store the binaries of their packages.

    Then check Go env

    You system must have $GOPATH and $GOROOT, below is my Env:

    GOARCH="amd64"
    GOBIN=""
    GOCHAR="6"
    GOEXE=""
    GOHOSTARCH="amd64"
    GOHOSTOS="linux"
    GOOS="linux"
    GOPATH="/home/elpsstu/gocode"
    GORACE=""
    GOROOT="/home/pravin/go"
    GOTOOLDIR="/home/pravin/go/pkg/tool/linux_amd64"
    CC="gcc"
    GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
    CXX="g++"
    CGO_ENABLED="1"
    

    Now, you run download go package:

    go get [-d] [-f] [-fix] [-t] [-u] [build flags] [packages]
    

    Get downloads and installs the packages named by the import paths, along with their dependencies. For more details you can look here.

提交回复
热议问题