dockergodockerfiletaralpine-linux

How to install Go in alpine linux


I am trying to install Go inside an Alpine Docker image. For that I downloaded tar file from here inside my alpine docker image, untar it using following command:

tar -C /usr/local -xzf go1.10.3.linux-amd64.tar.gz

exported PATH to have go binary as:

export PATH=$PATH:/usr/local/go/bin

However, when I say go version then it says that sh: go: not found. I am quite new to alpine. Does anyone know, what I am missing here?

Steps to reproduce-

$ docker run -it alpine sh
$ wget https://dl.google.com/go/go1.10.3.linux-amd64.tar.gz
$ tar -C /usr/local -xzf go1.10.3.linux-amd64.tar.gz
$ export PATH=$PATH:/usr/local/go/bin
$ go version

Solution

  • Thanks BMitch.

    I compiled the go source code and performed the below steps inside alpine image container.

    echo "installing go version 1.10.3..." 
    apk add --no-cache --virtual .build-deps bash gcc musl-dev openssl go 
    
    # download go tar 
    wget -O go.tgz https://dl.google.com/go/go1.10.3.src.tar.gz 
    tar -C /usr/local -xzf go.tgz 
    cd /usr/local/go/src/ 
    
    # compile code
    ./make.bash 
    export PATH="/usr/local/go/bin:$PATH"
    export GOPATH=/opt/go/ 
    export PATH=$PATH:$GOPATH/bin 
    apk del .build-deps 
    go version