Skip to content

Instantly share code, notes, and snippets.

@lalyos
Last active July 27, 2023 11:59
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save lalyos/2d8484cf5d9d030bd9d08e190818eb3f to your computer and use it in GitHub Desktop.
Save lalyos/2d8484cf5d9d030bd9d08e190818eb3f to your computer and use it in GitHub Desktop.
install golang to ubuntu/debian one-linet

Install latest golang

curl -Ls http://bit.ly/go_installer | bash

Overview

If you want to install golang, normally you are following the description on the official dowload page

There is a WIP tool for installing golang in a machine/os independent way called getgo. Source is available on github

One-liner

There is github issue describint the rational, and work behind the one-liner install. The README.md advices the following (works for linux/osx/windows):

curl -LO https://get.golang.org/$(uname)/go_installer && chmod +x go_installer && ./go_installer && rm go_installer

One-liner (linux)

But if you check the server logic you can see, that it only checks if the url is matched containsIgnoreCase agains MINGW/Linux/Darwin. So the url can be just: https://get.golang.org/$(uname). Curl can follow redirects, so curl -Lo installer get.golang.org/linux

So for cloud servers and/or docker containers you can do:

curl -Lo go_installer https://get.golang.org/linux && chmod +x go_installer && ./go_installer && rm go_installer
curl -Ls http://bit.ly/go_installer | bash

Download

The one-liner is capable of doing the following steps (also interactively):

  • chooseVersion
  • downloadGo
  • unzip
  • setupGOPATH

If you want only the download part, on linux it would be :

VERSION=go1.9.3
curl -L https://dl.google.com/go/go1.9.3.linux-amd64.tar.gz | tar -xz -C /usr/local

# old url
# curl -L https://storage.googleapis.com/golang/$VERSION.linux-amd64.tar.gz

Alpine linux

The binary linux distribution is normally dynamically lnked to glibc. It menas that the all above will fail on alpine. There are 2 workarounds:

  • Use frolvlad/alpine-glibc instead of library/alpine as a base image
  • Download the releavant docker image layer from golang:alpine : code here

References

curl -Lo go_installer https://get.golang.org/$(uname) && chmod +x go_installer && ./go_installer && rm go_installer
sudo bash -c 'add-apt-repository ppa:ubuntu-lxc/lxd-stable; sudo apt-get -qq update;sudo apt-get install -y golang'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment