Problem installing newest version of golang

Hi Guys, I am new to Go programming language. I wanted to install the latest version of go on my Ubuntu 18.04.3. I already had golang-1.10 on my system. I searched online and got to know to install the latest version of go you just write “sudo apt-get install golang-go”. However it says golang-go is already the newest version. I know there are other methods through which i can install golang-1.13. But my question here is why the latest version doesn’t get installed automatically with apt-get.

2 Likes

Because canonical has not yet updated it.

It is a common problem that packages in those big distros are a bit “dated”. This is mainly, because the distributors want to test packages first.

According to the Ubuntu installation instructions on the golang wiki there seems to be a PPA available, if you trust its owner, you can install from there.

If you do not trust the owners of the PPA you could still the officially proposed way of just extracting the tarball into your local harddisk. Remember though, that you need to update that go manually then, and updating means, deleting the old and extracting the new.

Alternatively you could use distribution that catches up faster, though they usually need a lot of knowledge about linux and the system they are installed on, or work different to how one might be used to:

  • Gentoo and derivates (compiles everything from source, installations and updates usually take a very long time, needs deep knowledge of linux and the system its installed on)
  • Arch and derivates (usually not more than 2 or 3 weeks behind upstream updates, also you can easily report outdated packages through the websites package catalog, similar to Gentoo you need a deep understanding of linux and your system)
  • nixOS (I have not yet any experience how quick they update, but so far its been current enough for me, this works totally different from any other linux distribution, as you usually do not install packages on the fly, but through a system/user config file) (The nixOS package manager nix can also be installed and used on a Ubuntu and could also used for on-the-fly or ad-hoc installations, though its not intended to work like that, but using purified environments to develop in, similar to how pyenv works but with a much stronger control than just sandboxing the pip target folder)
2 Likes

I’m using Ubuntu, but I don’t use the Go provided with apt because it is usually outdated as @NobbZ already said. I use a script I wrote to change go version by downloading it from the Go download page.

Before using it, you have to remove the go installed with apt: sudo apt-get remove golang-go.

How to install the script and make go installed this way to work:

  • save the script below in a file named go-upgrade
  • set it as executable: chmod ugo+x go-upgrade
  • move it to /usr/local/bin: sudo mv go-upgrade /usr/local/bin
  • add the following lines in the file ~/.bash_aliases. Create the file if it doesn’t exist. Execute it: source ~/.bash_aliases
# -- GOLANG --
export GOROOT="/usr/local/go"
export GOPATH="$HOME/go"
mkdir -p "$GOPATH/src" "$GOPATH/pkg" "$GOPATH/bin"
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

To use it: go-upgrade go1.13.4. This will install the latest version.

The bash script of go-upgrade:

#!/bin/bash
if [ $# -ne "1" ]; then
    echo "expect single argument (e.g. go1.13.3)"
    exit 1
fi
rm -f /tmp/$1.linux-amd64.tar.gz
wget -q https://dl.google.com/go/$1.linux-amd64.tar.gz -P/tmp
if [ $? -ne "0" ]; then
    echo "failed downloading" $1.linux-amd64.tar.gz
    exit 1
fi
if [ -e /usr/local/go ]; then
	go version >& /dev/null
    if [ $? -eq "0" ]; then
         echo "old version:" `go version | cut "-d " -f3`   
    fi
    sudo rm -rf /usr/local/go
fi
sudo tar -C /usr/local -xzf /tmp/$1.linux-amd64.tar.gz
rm /tmp/$1.linux-amd64.tar.gz
echo "new version:" `go version | cut "-d " -f3`
2 Likes

Why not using something that has already been widely tested and is used by a large community like asdf-vm and it’s golang plugin. I use it regularly to manage many languages at the same time for my projects.

2 Likes

I’m currently maintaining a Linux based Bash script that install Go based on the official documentation. Feel free to use it as I’m testing it daily in my nightly CI build. See print_help section for instruction or just run ./gosetup.bash -h.

Hmm, something new. Thanks for the intro. :+1:

Why bash over something else? I often use bash script over something else mainly because I do have to install anything else just to get things done. However, that’s not for every deployment scenario. asdf should be very useful without getting through the hassle to reinstall every release.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.