首页 > 解决方案 > 从源代码安装 Mongo 工具

问题描述

我正在安装 MongoDB,我需要 mongoimport。我已经从源MongoDB安装了 MongoDB 本身。我仍然需要mongoimport,它是mongo-tools mongo-tools github的一部分。其中说明了一些说明,我已经克隆了存储库,进入它(/ssd/[MYNAME]/mongoinstall/mongo-tools)并运行

. ./set_goenv.sh

回购状态的自述文件可以运行. ./set_gopath.sh,但这个不存在。

虽然我不觉得该命令做了任何事情,因为 go env没有改变。

我也从源代码安装了 GO。

go build -o bin/mongoimport mongoimport/main/mongoimport.go

返回以下错误:

mongoimport/main/mongoimport.go:13:2: cannot find package "github.com/mongodb/mongo-tools-common/log" in any of:
    /ssd/[MYNAME]/mongoinstall/go/src/github.com/mongodb/mongo-tools-common/log (from $GOROOT)
    /export/scratch1/home/gast141/go/src/github.com/mongodb/mongo-tools-common/log (from $GOPATH)
mongoimport/main/mongoimport.go:14:2: cannot find package "github.com/mongodb/mongo-tools-common/signals" in any of:
    /ssd/[MYNAME]/mongoinstall/go/src/github.com/mongodb/mongo-tools-common/signals (from $GOROOT)
    /export/scratch1/home/gast141/go/src/github.com/mongodb/mongo-tools-common/signals (from $GOPATH)
mongoimport/main/mongoimport.go:15:2: cannot find package "github.com/mongodb/mongo-tools-common/util" in any of:
    /ssd/[MYNAME]/mongoinstall/go/src/github.com/mongodb/mongo-tools-common/util (from $GOROOT)
    /export/scratch1/home/gast141/go/src/github.com/mongodb/mongo-tools-common/util (from $GOPATH)
mongoimport/main/mongoimport.go:16:2: cannot find package "github.com/mongodb/mongo-tools/mongoimport" in any of:
    /ssd/[MYNAME]/mongoinstall/go/src/github.com/mongodb/mongo-tools/mongoimport (from $GOROOT)
    /export/scratch1/home/gast141/go/src/github.com/mongodb/mongo-tools/mongoimport (from $GOPATH)

我努力了

./build.sh

但它惊呼:

GOROOT not set and preferred GOROOT '/ssd/[MYNAME]/mongoinstall/go/bin/go' doesn't exist. Aborting. 

的输出go env是:

GOARCH="amd64"
GOBIN=""
GOCACHE="/export/scratch1/home/gast141/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/export/scratch1/home/gast141/go"
GOPROXY=""
GORACE=""
GOROOT="/ssd/[MYNAME]/mongoinstall/go"
GOTMPDIR=""
GOTOOLDIR="/ssd/[MYNAME]/mongoinstall/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build916816613=/tmp/go-build -gno-record-gcc-switches"

我在Fedora release 28 (Twenty Eight)

我怎样才能让 mongoimport 工作?

标签: mongodbinstallationmongoimport

解决方案


我在 Mac 系统上尝试编译 mongotools 时遇到了同样的错误。就我而言,问题是set_gopath.sh(对于 mongotools 版本 3.6.5)与我使用的 shell 不兼容(fish)。该脚本导出GOPATH环境变量,但一旦回到环境中,它似乎不会保留其适当的变量fish

我尝试bash在持久性 bash shell 中运行set_gopath.sh,然后运行go build命令,但结果是相同的问题。

我发现一个成功的解决方法是修改set_gopath.sh并在最后包含go build命令。运行set_gopath.sh然后设置环境并成功运行 go 命令。


推荐阅读