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.
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)
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
- set it as executable:
chmod ugo+x go-upgrade
- move it to
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:
# -- 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
#!/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`
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.
wiki: recommended Ubuntu port still does not have security fix release #35090
FWIW, running in console mode a recent package generation (different distro) of 1.13.3 took about 1 hour and 42 minutes on the below.
$ uname -mp i686 Intel(R) Atom(TM) CPU N270 @ 1.60GHz $ free --giga | perl -lae 'print @F[0,1] if $. == 2' Mem:1 $ gcc --version | head -n 1 gcc (GCC) 5.5.0 $
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
Hmm, something new. Thanks for the intro.
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.
Presuming that your cited golang-1.10 was factually from the above, as your intention appears to be to uninstall 1.10 and install a 1.13.x series, it could be mentioned (in your context) that to avert potential dependency conflicts, one might avoid using
apt-get to obtain golang subrepositories, where these would be installed globally, and the option of running, e.g.,
go get -u golang.org/x/net, would install locally the named updated subrepository.
Where 3rd party software is involved, which might include bindings (or an interface) to a recent Golang release, the preceeding likewise would potentially be applicable, that is, one might be stuck with manually installing such software.