我正在开发一个 golang 程序,直到昨天它都运行正常,今天早上我做了一些修改,并进行了构建,一切都很好,然后我尝试通过命令行运行该程序,但出现了这条消息
k@kM:~/Projects/co-lib$ go run main.go
khaled@khaledM:~/Projects/co-lib$ go run main.go
Command 'go' not found, but can be installed with:
sudo snap install go # version 1.17.3, or
sudo apt install golang-go # version 2:1.13~1ubuntu2
sudo apt install gccgo-go # version 2:1.13~1ubuntu2
See 'snap info go' for additional versions.
然后尝试重新安装它,但是哎呀!我播下此消息:
[sudo] password for khaled:
error: This revision of snap "go" was published using classic confinement and
thus may perform arbitrary system changes outside of the security
sandbox that snaps are usually confined to, which may put your system at
risk.
If you understand and want to proceed repeat the command including
--classic.
然后下载最新版本并尝试按照此顺序安装
sudo apt install go1.17.3.linux-amd64.tar.gz
但它再次显示另一条消息:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package go.1.17.3.linux-amd64.tar.gz
E: Couldn't find any package by glob 'go.1.17.3.linux-amd64.tar.gz'
告诉我!下载文件的位置就在主目录中!
我完全糊涂了,请帮帮我
答案1
你可以使用 apt 安装(稍旧一些的)版本,
sudo apt install golang
或者,使用Golang 反向移植PPA,为 Ubuntu 18.04+ 托管最新版本的 golang。
sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt update
sudo apt install golang-1.17
您也可以使用 snap 安装最新版本,
sudo snap install go --classic