Score:-2

How to install the latest version of golang in Ubuntu?

in flag

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

sarlacii avatar
pm flag
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.
Score:7
us flag

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
chx101 avatar
za flag
Does Google or the Go team maintain an active repository?
us flag
I don't know. However, the snap provides the latest version
chx101 avatar
za flag
Coo. The problem with Snap is that it's buggy on my machine plus I just behaves weirdly so I try to avoid it at all costs
us flag
@chx101 I have updated the answer. You can use the PPA to avoid snap.
yshehab avatar
pf flag
The backports work for WSL too.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.