我是go编程语言的新手。
我在my-s3zipper.go程序中使用下面的包。
"github.com/AdRoll/goamz/aws"
"github.com/AdRoll/goamz/s3"当我用本地用户运行我的go程序时,它运行得很好。下面是go run命令。
go run my-s3zipper.go
Running on port 80当我用sudo运行我的go程序时,它没有运行并且抛出错误。下面是使用sudo的go run命令。
sudo go run my-s3zipper.go
my-s3zipper.go:19:5: cannot find package "github.com/AdRoll/goamz/aws" in any of:
/usr/lib/golang/src/github.com/AdRoll/goamz/aws (from $GOROOT)
/root/go/src/github.com/AdRoll/goamz/aws (from $GOPATH)
my-s3zipper.go:20:5: cannot find package "github.com/AdRoll/goamz/s3" in any of:
/usr/lib/golang/src/github.com/AdRoll/goamz/s3 (from $GOROOT)
/root/go/src/github.com/AdRoll/goamz/s3 (from $GOPATH)
my-s3zipper.go:21:5: cannot find package "github.com/garyburd/redigo/redis" in any of:
/usr/lib/golang/src/github.com/garyburd/redigo/redis (from $GOROOT)
/root/go/src/github.com/garyburd/redigo/redis (from $GOPATH)有人能帮我解决这个问题吗?
谢谢
发布于 2019-04-25 16:49:49
这可能会行得通
sudo -E go run my-s3zipper.go从sudo手册页
-E‘-E (保留环境)选项向安全策略指示用户希望保留其现有环境变量。如果指定了-E选项,而用户没有保留环境的权限,则安全策略可能会返回错误。
发布于 2019-04-25 16:24:04
尝试:
sudo GOPATH="$GOPATH:/your/home/go/path" go run my-s3zipper.go或
su
GOPATH="$GOPATH:/your/home/go/path"
go run my-s3zipper.go原因可能是您的用户和root的GOPATH变量不同。
您可以通过在用户登录时执行echo $GOPATH来检测/your/home/go/path
https://stackoverflow.com/questions/55843277
复制相似问题