This is the documentation for the latest (main) development branch of Zephyr. If you are looking for the documentation of previous releases, use the drop-down menu on the left and select the desired version.

Install Linux Host Dependencies

Documentation is available for these Linux distributions:

  • Ubuntu

  • Fedora

  • Clear Linux

  • Arch Linux

For distributions that are not based on rolling releases, some of the requirements and dependencies may not be met by your package manager. In that case please follow the additional instructions that are provided to find software from sources other than the package manager.

Note

If you’re working behind a corporate firewall, you’ll likely need to configure a proxy for accessing the internet, if you haven’t done so already. While some tools use the environment variables http_proxy and https_proxy to get their proxy settings, some use their own configuration files, most notably apt and git.

Update Your Operating System

Ensure your host system is up to date.

sudo apt-get update
sudo apt-get upgrade

Install Requirements and Dependencies

Note that both Ninja and Make are installed with these instructions; you only need one.

sudo apt-get install --no-install-recommends git cmake ninja-build gperf \
  ccache dfu-util device-tree-compiler wget \
  python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file libpython3.8-dev \
  make gcc gcc-multilib g++-multilib libsdl2-dev

CMake

A recent CMake version is required. Check what version you have by using cmake --version. If you have an older version, there are several ways of obtaining a more recent one:

  • On Ubuntu, you can follow the instructions for adding the kitware third-party apt repository to get an updated version of cmake using apt.

  • Download and install a packaged cmake from the CMake project site. (Note this won’t uninstall the previous version of cmake.)

    cd ~
    wget https://github.com/Kitware/CMake/releases/download/v3.15.3/cmake-3.15.3-Linux-x86_64.sh
    chmod +x cmake-3.15.3-Linux-x86_64.sh
    sudo ./cmake-3.15.3-Linux-x86_64.sh --skip-license --prefix=/usr/local
    hash -r
    

    The hash -r command may be necessary if the installation script put cmake into a new location on your PATH.

  • Download and install from the pre-built binaries provided by the CMake project itself in the CMake Downloads page. For example, to install version 3.13.1 in ~/bin/cmake:

    mkdir $HOME/bin/cmake && cd $HOME/bin/cmake
    wget https://github.com/Kitware/CMake/releases/download/v3.13.1/cmake-3.13.1-Linux-x86_64.sh
    yes | sh cmake-3.13.1-Linux-x86_64.sh | cat
    echo "export PATH=$PWD/cmake-3.13.1-Linux-x86_64/bin:\$PATH" >> $HOME/.zephyrrc
    
  • Use pip3:

    pip3 install --user cmake
    

    Note this won’t uninstall the previous version of cmake and will install the new cmake into your ~/.local/bin folder so you’ll need to add ~/.local/bin to your PATH. (See Python and pip for details.)

  • Check your distribution’s beta or unstable release package library for an update.

  • On Ubuntu you can also use snap to get the latest version available:

    sudo snap install cmake
    

After updating cmake, verify that the newly installed cmake is found using cmake --version. You might also want to uninstall the CMake provided by your package manager to avoid conflicts. (Use whereis cmake to find other installed versions.)

DTC (Device Tree Compiler)

A recent DTC version is required. Check what version you have by using dtc --version. If you have an older version, either install a more recent one by building from source, or use the one that is bundled in the Zephyr SDK by installing it.

Python

A modern Python 3 version is required. Check what version you have by using python3 --version.

If you have an older version, you will need to install a more recent Python 3. You can build from source, or use a backport from your distribution’s package manager channels if one is available. Isolating this Python in a virtual environment is recommended to avoid interfering with your system Python.

Install the Zephyr Software Development Kit (SDK)

Use of the Zephyr SDK is optional, but recommended. Some of the dependencies installed above are only needed for installing the SDK.

Zephyr’s SDK contains all necessary tools to build Zephyr on all supported architectures. Additionally, it includes host tools such as custom QEMU binaries and a host compiler. The SDK supports the following target architectures:

  • X86

  • Arm

  • ARC

  • Nios II

  • RISC-V

  • SPARC

  • Xtensa

Follow these steps to install the Zephyr SDK:

  1. Download the latest SDK as a self-extracting installation binary:

    wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.12.4/zephyr-sdk-0.12.4-x86_64-linux-setup.run
    

    (You can change 0.12.4 to another version if needed; the Zephyr Downloads page contains all available SDK releases.)

  2. Run the installation binary, installing the SDK at ~/zephyr-sdk-0.12.4:

    cd <sdk download directory>
    chmod +x zephyr-sdk-0.12.4-x86_64-linux-setup.run
    ./zephyr-sdk-0.12.4-x86_64-linux-setup.run -- -d ~/zephyr-sdk-0.12.4
    

    You can pick another directory if you want. If this fails, make sure Zephyr’s dependencies were installed as described in Install Requirements and Dependencies.

If you ever want to uninstall the SDK, just remove the directory where you installed it.

Note

It is recommended to install the Zephyr SDK at one of the following locations:

  • $HOME/zephyr-sdk[-x.y.z]

  • $HOME/.local/zephyr-sdk[-x.y.z]

  • $HOME/.local/opt/zephyr-sdk[-x.y.z]

  • $HOME/bin/zephyr-sdk[-x.y.z]

  • /opt/zephyr-sdk[-x.y.z]

  • /usr/zephyr-sdk[-x.y.z]

  • /usr/local/zephyr-sdk[-x.y.z]

where [-x.y.z] is optional text, and can be any text, for example -0.12.4.

If you install the Zephyr SDK outside any of those locations, then it is required to register the Zephyr SDK in the CMake package registry during installation or set ZEPHYR_SDK_INSTALL_DIR to point to the Zephyr SDK installation folder.

ZEPHYR_SDK_INSTALL_DIR can also be used for pointing to a folder containing multiple Zephyr SDKs, allowing for automatic toolchain selection, for example: ZEPHYR_SDK_INSTALL_DIR=/company/tools

  • /company/tools/zephyr-sdk-0.12.4

  • /company/tools/zephyr-sdk-a.b.c

  • /company/tools/zephyr-sdk-x.y.z

this allow Zephyr to pick the right toolchain, while allowing multiple Zephyr SDKs to be grouped together at a custom location.

Building on Linux without the Zephyr SDK

The Zephyr SDK is provided for convenience and ease of use. It provides toolchains for all Zephyr target architectures, and does not require any extra flags when building applications or running tests. In addition to cross-compilers, the Zephyr SDK also provides prebuilt host tools. It is, however, possible to build without the SDK’s toolchain by using another toolchain as as described in the main Getting Started Guide document.

As already noted above, the SDK also includes prebuilt host tools. To use the SDK’s prebuilt host tools with a toolchain from another source, you must set the ZEPHYR_SDK_INSTALL_DIR environment variable to the Zephyr SDK installation directory. To build without the Zephyr SDK’s prebuilt host tools, the ZEPHYR_SDK_INSTALL_DIR environment variable must be unset.

To make sure this variable is unset, run:

unset ZEPHYR_SDK_INSTALL_DIR