关于“sudo go run main.go” [英] About "sudo go run main.go"
问题描述
我在Ubuntu 16.04中使用Go,并设置了 GOPATH
, GOROOT
并成功运行简单代码。 / p>
现在我想通过gopacket捕获网络数据包,但它需要sudo / root权限。我执行命令: sudo go run main.go
,它回显错误:
exec:go:在$ PATH中找不到的可修改文件
我使用Google搜索并编辑文件 / etc / sudoders
并将行Defaults env_reset
更改为Defaults!env_reset
,但它不起作用......
你能帮我吗?
<你的环境变量没有为你的root用户设置。不要尝试运行 sudo go run ...
,而不是建立没有sudo的二进制文件,例如 go build
或 go install
,然后使用 sudo $ c $执行二进制文件假设你在
: main.go
的文件夹中,假设它被称为<$ c>。 $ c> mycapt
go build
sudo ./mycapt
或:
go install
sudo $ GOPATH / bin / mycapt
I use Go in my Ubuntu 16.04, and I set GOPATH
, GOROOT
and run simple code successfully.
Now I want to capture network packet by "gopacket", but it needs sudo /root permission. I excute command: sudo go run main.go
, it echo error:
"exec: go: excutable file not found in $PATH"
I googled it and I edit file /etc/sudoders
and change line "Defaults env_reset"
to "Defaults !env_reset"
, but it not work...
Can you help me?
Your environment variables are not set for your root user. Don't try to run sudo go run ...
, instead build the binary without sudo, e.g. go build
or go install
, and then execute the binary with sudo
.
Let's say you're in the folder of main.go
, assumed it's called mycapt
:
go build
sudo ./mycapt
Or:
go install
sudo $GOPATH/bin/mycapt
这篇关于关于“sudo go run main.go”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!