Installing Microchip XC8 on Linux

How to install Microchip XC8 compiler for PIC microcontrollers on Linux


Sometimes the fully featured MPLAB X IDE is a bit overkill for simple PIC projects. This guide explains how to install just the XC8 compiler on Linux. With XC8 installed, you can programme PICs using a basic text editor.

See also, PICkit2 Software on Linux.

Installing Microchip XC8 Compiler on Linux

Microchip XC8 compiler licenses can be purchased for improved optimisation, but you can use the free version (as I do) without any other limitations.

1. Download XC8

You can download XC8 on the Microchip compilers webpage (scroll down, select the "Compiler Downloads" tab, click "MPLAB XC8 Compiler vx.xx" in the Linux section).

2. Install XC8

These are the commands I had to run to install the XC8 compiler (I downloaded the XC8 installer into my Downloads folder):

sudo apt install lib32ncurses5
cd ~/Downloads
sudo chmod u+x
sudo ./ 

lib32ncurses5 may or may not be required by the XC8 installer. Try installing XC8 without lib32ncurses5 first - if it doesn't work, then install lib32ncurses5 and try again.

Once the XC8 installer starts, you will be prompted to agree to the license agreement which we have to do if we want to use XC8. Then select license type 1 (free), then confirm the installation directory (/opt/microchip/xc8/2.10) by pressing enter. Enter "y" to apply settings to all users of your machine. Enter "y" again to add XC8 to the PATH environment variable (so we can run XC8 in a terminal by typing just xc8 rather than the full /opt/microchip/xc8/2.10/bin/xc8). Finally press enter again when prompted to begin the installation. Once installed, enter "n" to decline purchasing a PRO license, and again to decline the free 60-day evaluation of the PRO license, and again to avoid activating a license. Press enter to agree the host ID. XC8 should now be installed on our system.

3. Check XC8 was installed correctly

Close and re-open the terminal so that the above-mentioned PATH environment variable loads, then type xc8-cc --version to check it installed okay. You should see something like this:

Check XC8 installed correctly

Check XC8 installed correctly

You can check the compiler actually works with the following programme:

#include <xc.h>
int main() {
    return 0;

Save the above to a file named "main.c", navigate to its directory and compile with:

xc8-cc -mcpu=18f46k22 main.c

You should see something like this:

Testing XC8 actually works

Testing XC8 actually works