Golang的获取命令失败

时间:2019-09-05 03:52:23

标签: go

我使用此命令从GitHub下载软件包;但是输出令我惊讶,我想安装该软件包而不是在GOPATH或GOROOT下找到该软件包!

$ go get  github.com/golang/dep/cmd/dep

package github.com/golang/dep/cmd/dep: cannot find package "github.com/golang/dep/cmd/dep" in any of:
    /usr/local/Cellar/go/1.13/libexec/src/github.com/golang/dep/cmd/dep (from $GOROOT)
    /Users/mateuszhang/go/src/github.com/golang/dep/cmd/dep (from $GOPATH)

$ go get -u github.com/golang/dep/cmd/dep
package github.com/golang/dep/cmd/dep: cannot find package "github.com/golang/dep/cmd/dep" in any of:
    /usr/local/Cellar/go/1.13/libexec/src/github.com/golang/dep/cmd/dep (from $GOROOT)
    /Users/mateuszhang/go/src/github.com/golang/dep/cmd/dep (from $GOPATH)

我的环境

$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/mateuszhang/Library/Caches/go-build"
GOENV="/Users/mateuszhang/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH=":/Users/mateuszhang/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.13/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.13/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/_t/b4m17gg13x1d_s9dpkp65bfsb9ckh4/T/go-build928907869=/tmp/go-build -gno-record-gcc-switches -fno-common"

1 个答案:

答案 0 :(得分:1)

  

您可能需要将环境变量$GO111MODULE设置为on。您可以通过在bash个人资料文件(即export GO111MODULE=on或〜/ .profile)末尾添加~/.bashrc来做到这一点。

是否要安装dep?运行:

go get -u github.com/golang/dep/cmd/dep

想从源代码安装吗?运行:

go get -d -u github.com/golang/dep
cd $(go env GOPATH)/src/github.com/golang/dep
DEP_LATEST=$(git describe --abbrev=0 --tags)
git checkout $DEP_LATEST
go install -ldflags="-X main.version=$DEP_LATEST" ./cmd/dep
git checkout master