/bin/sh: 1: gvm: not found

6.3k views Asked by At

Problem:

I'm attempting to create a Dockerfile that installs all the components to run Go, to install GVM (Go Version Management), and to install specific Go Versions.

Error:

When I try building the container with:

docker build -t ##### .

I get this error:

/bin/sh: 1: gvm: not found

The command '/bin/sh -c gvm install go1.4 -B' returned a non-zero code: 127

Installed here:

/root/.gvm/scripts/env/gvm
/root/.gvm/scripts/gvm
/root/.gvm/bin/gvm

What I tried:

It's clearly able to install GVM but unable to use it. Why? I thought maybe I needed to refresh the .bashrc or the .bash_profile ... but that didn't work, since they don't exist.

Dockerfile:

FROM #####/#####

#Installing Golang dependencies
RUN apt-get -y install curl git mercurial make binutils bison gcc build-essential

#Installing Golang

RUN ["/bin/bash", "-c", "bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)"]
#gvm does not exist here... why?
RUN gvm install go1.4 -B
RUN gvm use go1.4

Question:

Why does GVM not seem to be installed? How do I get rid of the error?

1

There are 1 answers

0
JimB On BEST ANSWER

Your shell is /bin/sh, but gvm puts its initialization in ~/.bashrc, and expects /bin/bash.

You need to source the gvm initialization scripts to run the commands from a non-interactive bash shell:

RUN ["/bin/bash", "-c", ". /root/.gvm/scripts/gvm && gvm install go1.4 -B"]
RUN ["/bin/bash", "-c", ". /root/.gvm/scripts/gvm && gvm use go1.4"]

Or even better might be to put the commands you want to execute in a single bash script and add that to the image.

#!/bin/bash
set -e

source /root/.gvm/scripts/gvm
gvm install go1.4
gvm use go1.4