Development Environment Setup on Linux

Important

This section only describes OS-specific setup instructions; it is the first step in the complete Zephyr Getting Started Guide.

This section describes how to set up a Zephyr development environment on the following Linux distributions:

  • Ubuntu 16.04 LTS or 18.04 LTS 64-bit
  • Fedora 28 64-bit
  • Clear Linux
  • Arch Linux

Where needed, instructions are given which only apply to specific Linux distributions.

Update Your Operating System

Ensure your host system is up to date before proceeding.

On Ubuntu:

sudo apt-get update
sudo apt-get upgrade

On Fedora:

sudo dnf upgrade

Note that having a newer version available for an installed package (as reported by dnf check-update) does not imply a subsequent dnf upgrade will install it, because it must also ensure dependencies and other restrictions are satisfied.

On Clear Linux:

sudo swupd update

On Arch Linux:

sudo pacman -Syu

Install Requirements and Dependencies

Install the following packages using your system’s package manager. Note that both Ninja and Make are installed; you may prefer only to install one.

On Ubuntu:

sudo apt-get install --no-install-recommends git cmake ninja-build gperf \
  ccache dfu-util device-tree-compiler wget \
  python3-pip python3-setuptools python3-wheel xz-utils file make

On Fedora:

sudo dnf group install "Development Tools" "C Development Tools and Libraries"
dnf install git cmake ninja-build gperf ccache dfu-util dtc wget \
  python3-pip xz file glibc-devel.i686 libstdc++-devel.i686

On Clear Linux:

sudo swupd bundle-add c-basic dev-utils dfu-util dtc \
  os-core-dev python-basic python3-basic

On Arch:

sudo pacman -S git cmake ninja gperf ccache dfu-util dtc wget \
    python-pip python-setuptools python-wheel xz file make

CMake version 3.8.2 or higher is required. Check what version you have using cmake --version; if you have an older version, check the backports or install a more recent version manually. For example, to install version 3.8.2 from the CMake website directly in ~/cmake:

mkdir $HOME/cmake && cd $HOME/cmake
wget https://cmake.org/files/v3.8/cmake-3.8.2-Linux-x86_64.sh
yes | sh cmake-3.8.2-Linux-x86_64.sh | cat
echo "export PATH=$PWD/cmake-3.8.2-Linux-x86_64/bin:\$PATH" >> $HOME/.zephyrrc
cmake --version

Install the Zephyr Software Development Kit (SDK)

Note

Use of the Zephyr SDK is optional, but recommended. Some of the requirements and dependencies in the previous section are only needed for installing the SDK.

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

  • X86
  • X86 IAMCU ABI
  • Arm
  • ARC
  • Nios II
  • Xtensa
  • RISC-V

Follow these steps to install the SDK on your Linux host system.

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

    wget https://github.com/zephyrproject-rtos/meta-zephyr-sdk/releases/download/0.9.3/zephyr-sdk-0.9.3-setup.run
    

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

  2. Run the installation binary:

    cd <sdk download directory>
    sh zephyr-sdk-0.9.3-setup.run
    

    Important

    If this fails, make sure Zephyr’s dependencies were installed as described in Install Requirements and Dependencies.

  3. Follow the installation instructions on the screen. The toolchain’s default installation location is /opt/zephyr-sdk/, but it is recommended to install the SDK under your home directory instead.

    To install the SDK in the default location, you need to run the installation binary as root.

  4. To use the Zephyr SDK, export the following environment variables and use the target location where SDK was installed:

    export ZEPHYR_TOOLCHAIN_VARIANT=zephyr
    export ZEPHYR_SDK_INSTALL_DIR=<sdk installation directory>
    

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, keep the ZEPHYR_SDK_INSTALL_DIR environment variable set 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 before you run source zephyr-env.sh later on in the Getting Started Guide.

To make sure this variable is unset, run:

unset ZEPHYR_SDK_INSTALL_DIR