About “sudo go run main.go”

后端 未结 2 1754
暗喜
暗喜 2020-12-22 05:50

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\

2条回答
  •  情书的邮戳
    2020-12-22 06:12

    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
    

提交回复
热议问题