The cleanest way to get a repeatable old tools building off the IDE is to put the toolchain in a Docker image, then call the compiler in batch mode with docker run. Build the image once and you get the exact same MPLAB X + XC8 versions on Windows, macOS, or Linux — no local install, no "but worked on my other machine."
Use a Dockerfile like the one below to bake in MPLAB, etc. in:
FROM ubuntu:20.04
# Build arguments for tool versions
ARG MPLABX_VERSION=6.20
ARG XC8_VERSION=2.46
# Set environment variables from build arguments
ENV MPLABX_VERSION=${MPLABX_VERSION}
ENV XC8_VERSION=${XC8_VERSION}
RUN echo "MPLABX Version: $MPLABX_VERSION"
RUN echo "XC8 Version: $XC8_VERSION"
# Set non-interactive mode for tzdata
ENV DEBIAN_FRONTEND=noninteractive
# Add i386 architecture for Microchip tools compatibility
RUN dpkg --add-architecture i386
# Install necessary dependencies including i386 libraries
RUN apt-get update -qq && apt-get install -y -qq \
wget \
tar \
sudo \
make \
gcc \
libusb-1.0-0 \
libc6:i386 \
libx11-6:i386 \
libxext6:i386 \
libstdc++6:i386 \
libexpat1:i386 \
&& rm -rf /var/lib/apt/lists/*
# Install java
RUN apt update && apt install -y default-jre
# Download and install MPLAB X
RUN wget -q --referer="https://www.microchip.com/en-us/tools-resources/develop/mplab-x-ide" \
-O /tmp/MPLABX-v${MPLABX_VERSION}-linux-installer.tar \
"https://ww1.microchip.com/downloads/aemDocuments/documents/DEV/ProductDocuments/SoftwareTools/MPLABX-v${MPLABX_VERSION}-linux-installer.tar" \
&& cd /tmp \
&& tar -xf MPLABX-v${MPLABX_VERSION}-linux-installer.tar \
&& mv "MPLABX-v${MPLABX_VERSION}-linux-installer.sh" mplabx \
&& chmod +x mplabx \
&& USER=root ./mplabx --nox11 -- --unattendedmodeui none --mode unattended --ipe 0 --collectInfo 0 \
--installdir /opt/mplabx --8bitmcu 1 --16bitmcu 1 --32bitmcu 0 --othermcu 0 \
&& rm -rf /tmp/mplabx /tmp/MPLABX-v${MPLABX_VERSION}-linux-installer.tar
# Download and install XC8 compiler
RUN wget -nv -O /tmp/xc8 \
"https://ww1.microchip.com/downloads/aemDocuments/documents/DEV/ProductDocuments/SoftwareTools/xc8-v${XC8_VERSION}-full-install-linux-x64-installer.run" \
&& chmod +x /tmp/xc8 \
&& /tmp/xc8 --mode unattended --unattendedmodeui none --netservername localhost \
--LicenseType FreeMode --prefix "/opt/microchip/xc8/v${XC8_VERSION}" \
&& rm -f /tmp/xc8
# Set up paths
ENV PATH="/opt/mplabx/mplab_platform/bin:/opt/microchip/xc8/v${XC8_VERSION}/bin:${PATH}"
# Set working directory
WORKDIR /workspace
# Default command shows XC8 version - users can override
CMD ["xc8-cc", "--version"]