8

i was working on a golang program and it was working correctly til yesterday, this morning i made some changes and get a build and every thing was fine then i tried to run the program through command line but this message showed up

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.

then tried to reinstall it , but oops ! i sow this message :

[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.

then downloaded the latest version and tried to install it with this order

sudo apt install go1.17.3.linux-amd64.tar.gz

but it shows another message again:

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'

blive me ! the location of the downloaded file is right in the home directory!

i am completely confused please help me

muru
  • 207,970
  • 5
    Hi, FYI "sudo apt install go1.17.3.linux-amd64.tar.gz" is incorrect. If you use the repos, then check "apt-cache search golang" for package names, then install via eg. "apt install golang-1.16" etc. If you download the source (not recommended), then you need to compile. You need to google the basics of Ubuntu package installation first. – sarlacii Nov 24 '21 at 08:51

1 Answers1

29

You can install the (slightly older) version with apt,

sudo apt install golang

Alternatively, use the Golang Backports PPA, which hosts the latest version of golang for Ubuntu 18.04+.

sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt update
sudo apt install golang-1.17 

You can also install the latest version with snap,

sudo snap install go  --classic
  • The backports work for WSL too. – yshehab Jul 18 '22 at 14:53
  • If you have installed older versions before after adding the ppa and running sudo apt update you can install the latest version with sudo apt upgrade. – ali Jul 09 '24 at 18:07