Software⏱️ 3 min read📅 2026-06-03

How to Fix: In a Dockerfile, How to update PATH environment variable?

Update PATH environment variable in Dockerfile

Quick Answer: Use the ENV instruction to set the PATH environment variable, like this: ENV PATH /opt/gtk/bin:$PATH

To update the PATH environment variable in a Dockerfile, you can use the ENV instruction to set the environment variable before running other commands. The issue with your current approach is that you are setting the PATH variable using the export command, which only affects the current shell session and not the image's environment.

✅ Best Solution

Method 1: Using ENV Instruction

  1. Step 1: Add the following line to your Dockerfile before running any commands that require the PATH variable:
ENV PATH /opt/gtk/bin:$PATH

This will set the PATH environment variable for all subsequent commands in your Dockerfile.

Example:

FROM ubuntu
ENV PATH /opt/gtk/bin:$PATH
RUN apt-get update
RUN apt-get install -y golang gcc make wget git libxml2-utils libwebkit2gtk-3.0-dev libcairo2 libcairo2-dev libcairo-gobject

Alternative Method 1: Using a RUN command with the --env option

  1. Step 1: Add the following line to your Dockerfile before running any commands that require the PATH variable:
RUN --env=PATH=/opt/gtk/bin:$PATH apt-get update

This will set the PATH environment variable for the current command only.

Method 2: Using a bash shell and setting the PATH variable in the .bashrc file

  1. Step 1: Add the following line to your Dockerfile before running any commands that require the PATH variable:
RUN apt-get update
RUN echo 'export PATH=$PATH:/opt/gtk/bin' >> /etc/profile.d/bashrc.sh

This will set the PATH environment variable for all subsequent commands in your Dockerfile.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions