Home > Backend Development > Golang > Why is 'go: not found' an Error When Installing Go on Alpine Linux?

Why is 'go: not found' an Error When Installing Go on Alpine Linux?

Mary-Kate Olsen
Release: 2024-11-16 09:53:03
Original
937 people have browsed it

Why is

Go Installation on Alpine Linux

Installing Go in an Alpine Linux Docker container can be challenging due to differences in the system structure compared to other Linux distributions. One common issue is that the downloaded Go binary may not be found when attempting to run commands.

Problem:

As described in the provided context, the user had issues installing Go in an Alpine Docker image and encountered the error "sh: go: not found" when running the "go version" command. The steps taken to install Go included downloading the tar file, untarring it, and modifying the PATH environment variable to include the Go binary's location.

Solution:

The suggested solution involved using multi-stage builds to copy the Go installation from a pre-built Golang Docker image. Here's a breakdown of the provided solution:

FROM XXX

COPY --from=golang:1.13-alpine /usr/local/go/ /usr/local/go/

ENV PATH="/usr/local/go/bin:${PATH}"
Copy after login

In this solution:

  1. FROM XXX: Specifies the base image for the first build stage. This image can be any suitable Alpine Linux image.
  2. COPY --from=golang:1.13-alpine /usr/local/go/ /usr/local/go/: Copies the Go installation from the official Golang Docker image (golang:1.13-alpine) into the first build stage's image.
  3. ENV PATH="/usr/local/go/bin:${PATH}": Modifies the PATH environment variable in the second build stage (the resulting image) to include the Go binary's location.

The above is the detailed content of Why is 'go: not found' an Error When Installing Go on Alpine Linux?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template