03 May, 2021

How to resolve the trouble that occurred when I install Go into the alpine image


Hi, everyone.

My name is Takashi Narikawa. I work as a software engineer at eureka, inc.

This post is my first post on my blog. This time, I would like to leave a memorandum about the trouble that occurred when I install Go into the alpine image.


If you want to install Go on an alpine-based image, use apk instead of wget or curl command

What I wanted to do

I want to auto-deploy lambda with apex command on codebuild (CI) with hashicorp / terraform image. Because I wrote lambda script in Go language, it is necessary to install Go and the hashicorp / terraform image.

What Trouble

hashicorp / terraform image is based on Alpine. I tried to install Go with buildspec.yml of AWS Codebuild as follows.

export GO_VERSION=1.12.4
wget https://storage.googleapis.com/golang/go{GO_VERSION}.linux-amd64.tar.gz
tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
go version

Then, when go version command was executed, the following error appeared.

sh: go: not found

How to resolve the trouble

docker-How to install Go in alpine Linux-Stack Overflow had a similar case, So it was helpful.

With Alpine, you have libmusl instead of Glibc. Alpine’s libmusl is not a 1 for 1 replacement. Code linked against Glibc will show a not found error which is actually from the dynamic linker. You can see what libraries are linked to the binary with ldd:

Apparently, the behavior of libmusl (Linux standard C library) included instead of Glibc seems to be different.

# ldd /usr/local/go/bin/go
        /lib64/ld-linux-x86-64.so.2 (0x7f63ceed1000)
        libpthread.so.0 => /lib64/ld-linux-x86-64.so.2 (0x7f63ceed1000)
        libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f63ceed1000)

I see, / usr / local / go / bin / go has a dynamic link to / lib64 / ld-linux-x86–64.so.2 and returned not found error.

This guy’s suggestion is to run Go binaries (do not download go itself) or Glibc (if you use CentOS or Debian), but I didn’t use either solution.

I solved it by downloading go with apk as follows.

apk add --update --no-cache vim git make musl-dev go curl
# Configure Go
export GOPATH=/root/go
export PATH=${GOPATH}/bin:/usr/local/go/bin:$PATH
export GOBIN=$GOROOT/bin
mkdir -p ${GOPATH}/src ${GOPATH}/bin
export GO111MODULE=on
go version


docker — How to install Go in alpine Linux — Stack Overflow


: Go