Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 873
Yogesh Jilhawar Avatar asked Aug 28 '18 11:08

Yogesh Jilhawar


People also ask

Does Alpine have Go?

We have successfully installed Go on Alpine Linux.


3 Answers

I just copied it over using multi stage builds, seems to be ok so far

FROM XXX   COPY --from=golang:1.13-alpine /usr/local/go/ /usr/local/go/   ENV PATH="/usr/local/go/bin:${PATH}" 
like image 86
Chad Grant Avatar answered Oct 17 '22 08:10

Chad Grant


The following Dockerfile worked for me. Simpler and more abstract.

FROM alpine:latest

RUN apk add --no-cache git make musl-dev go

# Configure Go
ENV GOROOT /usr/lib/go
ENV GOPATH /go
ENV PATH /go/bin:$PATH

RUN mkdir -p ${GOPATH}/src ${GOPATH}/bin

# Install Glide
RUN go get -u github.com/Masterminds/glide/...

WORKDIR $GOPATH

CMD ["make"]

source: https://raw.githubusercontent.com/mickep76/alpine-golang/master/Dockerfile

like image 23
Bevilaqua Avatar answered Oct 17 '22 06:10

Bevilaqua


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 
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/ 
./make.bash 
export PATH="/usr/local/go/bin:$PATH"
export GOPATH=/opt/go/ 
export PATH=$PATH:$GOPATH/bin 
apk del .build-deps 
go version
like image 39
Yogesh Jilhawar Avatar answered Oct 17 '22 07:10

Yogesh Jilhawar