1.. _installation_linux: 2 3Install Linux Host Dependencies 4############################### 5 6Documentation is available for these Linux distributions: 7 8* Ubuntu 9* Fedora 10* Clear Linux 11* Arch Linux 12 13For distributions that are not based on rolling releases, some of the 14requirements and dependencies may not be met by your package manager. In that 15case please follow the additional instructions that are provided to find 16software from sources other than the package manager. 17 18.. note:: If you're working behind a corporate firewall, you'll likely 19 need to configure a proxy for accessing the internet, if you haven't 20 done so already. While some tools use the environment variables 21 ``http_proxy`` and ``https_proxy`` to get their proxy settings, some 22 use their own configuration files, most notably ``apt`` and 23 ``git``. 24 25Update Your Operating System 26**************************** 27 28Ensure your host system is up to date. 29 30.. tabs:: 31 32 .. group-tab:: Ubuntu 33 34 .. code-block:: console 35 36 sudo apt-get update 37 sudo apt-get upgrade 38 39 .. group-tab:: Fedora 40 41 .. code-block:: console 42 43 sudo dnf upgrade 44 45 .. group-tab:: Clear Linux 46 47 .. code-block:: console 48 49 sudo swupd update 50 51 .. group-tab:: Arch Linux 52 53 .. code-block:: console 54 55 sudo pacman -Syu 56 57.. _linux_requirements: 58 59Install Requirements and Dependencies 60************************************* 61 62.. NOTE FOR DOCS AUTHORS: DO NOT PUT DOCUMENTATION BUILD DEPENDENCIES HERE. 63 64 This section is for dependencies to build Zephyr binaries, *NOT* this 65 documentation. If you need to add a dependency only required for building 66 the docs, add it to doc/README.rst. (This change was made following the 67 introduction of LaTeX->PDF support for the docs, as the texlive footprint is 68 massive and not needed by users not building PDF documentation.) 69 70Note that both Ninja and Make are installed with these instructions; you only 71need one. 72 73.. tabs:: 74 75 .. group-tab:: Ubuntu 76 77 .. code-block:: console 78 79 sudo apt-get install --no-install-recommends git cmake ninja-build gperf \ 80 ccache dfu-util device-tree-compiler wget \ 81 python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \ 82 make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1 83 84 .. group-tab:: Fedora 85 86 .. code-block:: console 87 88 sudo dnf group install "Development Tools" "C Development Tools and Libraries" 89 sudo dnf install cmake ninja-build gperf dfu-util dtc wget which \ 90 python3-pip python3-tkinter xz file python3-devel SDL2-devel 91 92 .. group-tab:: Clear Linux 93 94 .. code-block:: console 95 96 sudo swupd bundle-add c-basic dev-utils dfu-util dtc \ 97 os-core-dev python-basic python3-basic python3-tcl 98 99 The Clear Linux focus is on *native* performance and security and not 100 cross-compilation. For that reason it uniquely exports by default to the 101 :ref:`environment <env_vars>` of all users a list of compiler and linker 102 flags. Zephyr's CMake build system will either warn or fail because of 103 these. To clear the C/C++ flags among these and fix the Zephyr build, run 104 the following command as root then log out and back in: 105 106 .. code-block:: console 107 108 echo 'unset CFLAGS CXXFLAGS' >> /etc/profile.d/unset_cflags.sh 109 110 Note this command unsets the C/C++ flags for *all users on the 111 system*. Each Linux distribution has a unique, relatively complex and 112 potentially evolving sequence of bash initialization files sourcing each 113 other and Clear Linux is no exception. If you need a more flexible 114 solution, start by looking at the logic in 115 ``/usr/share/defaults/etc/profile``. 116 117 .. group-tab:: Arch Linux 118 119 .. code-block:: console 120 121 sudo pacman -S git cmake ninja gperf ccache dfu-util dtc wget \ 122 python-pip python-setuptools python-wheel tk xz file make 123 124CMake 125===== 126 127A :ref:`recent CMake version <install-required-tools>` is required. Check what 128version you have by using ``cmake --version``. If you have an older version, 129there are several ways of obtaining a more recent one: 130 131* On Ubuntu, you can follow the instructions for adding the 132 `kitware third-party apt repository <https://apt.kitware.com/>`_ 133 to get an updated version of cmake using apt. 134 135* Download and install a packaged cmake from the CMake project site. 136 (Note this won't uninstall the previous version of cmake.) 137 138 .. code-block:: console 139 140 cd ~ 141 wget https://github.com/Kitware/CMake/releases/download/v3.21.1/cmake-3.21.1-Linux-x86_64.sh 142 chmod +x cmake-3.21.1-Linux-x86_64.sh 143 sudo ./cmake-3.21.1-Linux-x86_64.sh --skip-license --prefix=/usr/local 144 hash -r 145 146 The ``hash -r`` command may be necessary if the installation script 147 put cmake into a new location on your PATH. 148 149* Download and install from the pre-built binaries provided by the CMake 150 project itself in the `CMake Downloads`_ page. 151 For example, to install version 3.21.1 in :file:`~/bin/cmake`: 152 153 .. code-block:: console 154 155 mkdir $HOME/bin/cmake && cd $HOME/bin/cmake 156 wget https://github.com/Kitware/CMake/releases/download/v3.21.1/cmake-3.21.1-Linux-x86_64.sh 157 yes | sh cmake-3.21.1-Linux-x86_64.sh | cat 158 echo "export PATH=$PWD/cmake-3.21.1-Linux-x86_64/bin:\$PATH" >> $HOME/.zephyrrc 159 160* Use ``pip3``: 161 162 .. code-block:: console 163 164 pip3 install --user cmake 165 166 Note this won't uninstall the previous version of cmake and will 167 install the new cmake into your ~/.local/bin folder so 168 you'll need to add ~/.local/bin to your PATH. (See :ref:`python-pip` 169 for details.) 170 171* Check your distribution's beta or unstable release package library for an 172 update. 173 174* On Ubuntu you can also use snap to get the latest version available: 175 176 .. code-block:: console 177 178 sudo snap install cmake 179 180After updating cmake, verify that the newly installed cmake is found 181using ``cmake --version``. 182You might also want to uninstall the CMake provided by your package manager to 183avoid conflicts. (Use ``whereis cmake`` to find other installed 184versions.) 185 186DTC (Device Tree Compiler) 187========================== 188 189A :ref:`recent DTC version <install-required-tools>` is required. Check what 190version you have by using ``dtc --version``. If you have an older version, 191either install a more recent one by building from source, or use the one that is 192bundled in the :ref:`Zephyr SDK <toolchain_zephyr_sdk>` by installing it. 193 194Python 195====== 196 197A :ref:`modern Python 3 version <install-required-tools>` is required. Check 198what version you have by using ``python3 --version``. 199 200If you have an older version, you will need to install a more recent Python 3. 201You can build from source, or use a backport from your distribution's package 202manager channels if one is available. Isolating this Python in a virtual 203environment is recommended to avoid interfering with your system Python. 204 205.. _pyenv: https://github.com/pyenv/pyenv 206 207Install the Zephyr Software Development Kit (SDK) 208************************************************* 209 210The Zephyr Software Development Kit (SDK) contains toolchains for each of 211Zephyr's supported architectures. It also includes additional host tools, such 212as custom QEMU and OpenOCD. 213 214Use of the Zephyr SDK is highly recommended and may even be required under 215certain conditions (for example, running tests in QEMU for some architectures). 216 217The Zephyr SDK supports the following target architectures: 218 219* ARC (32-bit and 64-bit; ARCv1, ARCv2, ARCv3) 220* ARM (32-bit and 64-bit; ARMv6, ARMv7, ARMv8; A/R/M Profiles) 221* MIPS (32-bit and 64-bit) 222* Nios II 223* RISC-V (32-bit and 64-bit; RV32I, RV32E, RV64I) 224* x86 (32-bit and 64-bit) 225* Xtensa 226 227Follow these steps to install the Zephyr SDK: 228 229#. Download and verify the `Zephyr SDK bundle`_: 230 231 .. parsed-literal:: 232 233 wget |sdk-url-linux| 234 wget -O - |sdk-url-linux-sha| | shasum --check --ignore-missing 235 236 You can change |sdk-version-literal| to another version if needed; the 237 `Zephyr SDK Releases`_ page contains all available SDK releases. 238 239 If your host architecture is 64-bit ARM (for example, Raspberry Pi), replace 240 ``x86_64`` with ``aarch64`` in order to download the 64-bit ARM Linux SDK. 241 242#. Extract the Zephyr SDK bundle archive: 243 244 .. parsed-literal:: 245 246 cd <sdk download directory> 247 tar xvf zephyr-sdk- |sdk-version-trim| _linux-x86_64.tar.xz 248 249#. Run the Zephyr SDK bundle setup script: 250 251 .. parsed-literal:: 252 253 cd zephyr-sdk- |sdk-version-ltrim| 254 ./setup.sh 255 256 If this fails, make sure Zephyr's dependencies were installed as described 257 in `Install Requirements and Dependencies`_. 258 259If you want to uninstall the SDK, remove the directory where you installed it. 260If you relocate the SDK directory, you need to re-run the setup script. 261 262.. note:: 263 It is recommended to extract the Zephyr SDK bundle at one of the following locations: 264 265 * ``$HOME`` 266 * ``$HOME/.local`` 267 * ``$HOME/.local/opt`` 268 * ``$HOME/bin`` 269 * ``/opt`` 270 * ``/usr/local`` 271 272 The Zephyr SDK bundle archive contains the ``zephyr-sdk-<version>`` 273 directory and, when extracted under ``$HOME``, the resulting installation 274 path will be ``$HOME/zephyr-sdk-<version>``. 275 276 If you install the Zephyr SDK outside any of these locations, you must 277 register the Zephyr SDK in the CMake package registry by running the setup 278 script, or set :envvar:`ZEPHYR_SDK_INSTALL_DIR` to point to the Zephyr SDK 279 installation directory. 280 281 You can also use :envvar:`ZEPHYR_SDK_INSTALL_DIR` for pointing to a 282 directory containing multiple Zephyr SDKs, allowing for automatic toolchain 283 selection. For example, ``ZEPHYR_SDK_INSTALL_DIR=/company/tools``, where 284 the ``company/tools`` folder contains the following subfolders: 285 286 * ``/company/tools/zephyr-sdk-0.13.2`` 287 * ``/company/tools/zephyr-sdk-a.b.c`` 288 * ``/company/tools/zephyr-sdk-x.y.z`` 289 290 This allows the Zephyr build system to choose the correct version of the 291 SDK, while allowing multiple Zephyr SDKs to be grouped together at a 292 specific path. 293 294.. _sdkless_builds: 295 296Building on Linux without the Zephyr SDK 297**************************************** 298 299The Zephyr SDK is provided for convenience and ease of use. It provides 300toolchains for all Zephyr target architectures, and does not require any extra 301flags when building applications or running tests. In addition to 302cross-compilers, the Zephyr SDK also provides prebuilt host tools. It is, 303however, possible to build without the SDK's toolchain by using another 304toolchain as described in the :ref:`toolchains` section. 305 306As already noted above, the SDK also includes prebuilt host tools. To use the 307SDK's prebuilt host tools with a toolchain from another source, you must set the 308:envvar:`ZEPHYR_SDK_INSTALL_DIR` environment variable to the Zephyr SDK 309installation directory. To build without the Zephyr SDK's prebuilt host tools, 310the :envvar:`ZEPHYR_SDK_INSTALL_DIR` environment variable must be unset. 311 312To make sure this variable is unset, run: 313 314.. code-block:: console 315 316 unset ZEPHYR_SDK_INSTALL_DIR 317 318.. _Zephyr SDK Releases: https://github.com/zephyrproject-rtos/sdk-ng/tags 319.. _CMake Downloads: https://cmake.org/download 320