linux-macos-setup.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. ********************************************
  2. Standard Toolchain Setup for Linux and macOS
  3. ********************************************
  4. :link_to_translation:`zh_CN:[中文]`
  5. Installation Step by Step
  6. =========================
  7. This is a detailed roadmap to walk you through the installation process.
  8. Setting up Development Environment
  9. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  10. These are the steps for setting up the ESP-IDF for your {IDF_TARGET_NAME}.
  11. * :ref:`get-started-prerequisites`
  12. * :ref:`get-started-get-esp-idf`
  13. * :ref:`get-started-set-up-tools`
  14. * :ref:`get-started-set-up-env`
  15. * :ref:`get-started-start-a-project`
  16. .. _get-started-prerequisites:
  17. Step 1. Install Prerequisites
  18. =============================
  19. In order to use ESP-IDF with the {IDF_TARGET_NAME}, you need to install some software packages based on your Operating System. This setup guide will help you on getting everything installed on Linux and macOS based systems.
  20. For Linux Users
  21. ~~~~~~~~~~~~~~~
  22. To compile using ESP-IDF you will need to get the following packages. The command to run depends on which distribution of Linux you are using:
  23. - Ubuntu and Debian::
  24. sudo apt-get install git wget flex bison gperf python3 python3-venv cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0
  25. - CentOS 7 & 8::
  26. sudo yum -y update && sudo yum install git wget flex bison gperf python3 cmake ninja-build ccache dfu-util libusbx
  27. CentOS 7 is still supported but CentOS version 8 is recommended for a better user experience.
  28. - Arch::
  29. sudo pacman -S --needed gcc git make flex bison gperf python cmake ninja ccache dfu-util libusb
  30. .. note::
  31. - CMake version 3.16 or newer is required for use with ESP-IDF. Run "tools/idf_tools.py install cmake" to install a suitable version if your OS versions doesn't have one.
  32. - If you do not see your Linux distribution in the above list then please check its documentation to find out which command to use for package installation.
  33. For macOS Users
  34. ~~~~~~~~~~~~~~~
  35. ESP-IDF will use the version of Python installed by default on macOS.
  36. - Install CMake & Ninja build:
  37. - If you have HomeBrew_, you can run::
  38. brew install cmake ninja dfu-util
  39. - If you have MacPorts_, you can run::
  40. sudo port install cmake ninja dfu-util
  41. - Otherwise, consult the CMake_ and Ninja_ home pages for macOS installation downloads.
  42. - It is strongly recommended to also install ccache_ for faster builds. If you have HomeBrew_, this can be done via ``brew install ccache`` or ``sudo port install ccache`` on MacPorts_.
  43. .. note::
  44. If an error like this is shown during any step::
  45. xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
  46. Then you will need to install the XCode command line tools to continue. You can install these by running ``xcode-select --install``.
  47. Apple M1 Users
  48. ~~~~~~~~~~~~~~
  49. If you use Apple M1 platform and see an error like this::
  50. WARNING: directory for tool xtensa-esp32-elf version esp-2021r2-patch3-8.4.0 is present, but tool was not found
  51. ERROR: tool xtensa-esp32-elf has no installed versions. Please run 'install.sh' to install it.
  52. or::
  53. zsh: bad CPU type in executable: ~/.espressif/tools/xtensa-esp32-elf/esp-2021r2-patch3-8.4.0/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc
  54. Then you will need to install Apple Rosetta 2 by running
  55. .. code-block:: bash
  56. /usr/sbin/softwareupdate --install-rosetta --agree-to-license
  57. Installing Python 3
  58. ~~~~~~~~~~~~~~~~~~~
  59. Based on macOS `Catalina 10.15 release notes`_, use of Python 2.7 is not recommended and Python 2.7 will not be included by default in future versions of macOS. Check what Python you currently have::
  60. python --version
  61. If the output is like ``Python 2.7.17``, your default interpreter is Python 2.7. If so, also check if Python 3 isn't already installed on your computer::
  62. python3 --version
  63. If the above command returns an error, it means Python 3 is not installed.
  64. Below is an overview of the steps to install Python 3.
  65. - Installing with HomeBrew_ can be done as follows::
  66. brew install python3
  67. - If you have MacPorts_, you can run::
  68. sudo port install python38
  69. .. _get-started-get-esp-idf:
  70. Step 2. Get ESP-IDF
  71. ===================
  72. To build applications for the {IDF_TARGET_NAME}, you need the software libraries provided by Espressif in `ESP-IDF repository <https://github.com/espressif/esp-idf>`_.
  73. To get ESP-IDF, navigate to your installation directory and clone the repository with ``git clone``, following instructions below specific to your operating system.
  74. Open Terminal, and run the following commands:
  75. .. include-build-file:: inc/git-clone-bash.inc
  76. ESP-IDF will be downloaded into ``~/esp/esp-idf``.
  77. Consult :doc:`/versions` for information about which ESP-IDF version to use in a given situation.
  78. .. _get-started-set-up-tools:
  79. Step 3. Set up the tools
  80. ========================
  81. Aside from the ESP-IDF, you also need to install the tools used by ESP-IDF, such as the compiler, debugger, Python packages, etc, for projects supporting {IDF_TARGET_NAME}.
  82. .. code-block:: bash
  83. cd ~/esp/esp-idf
  84. ./install.sh {IDF_TARGET_PATH_NAME}
  85. or with Fish shell
  86. .. code-block:: fish
  87. cd ~/esp/esp-idf
  88. ./install.fish {IDF_TARGET_PATH_NAME}
  89. The above commands install tools for {IDF_TARGET_NAME} only. If you intend to develop projects for more chip targets then you should list all of them and run for example:
  90. .. code-block:: bash
  91. cd ~/esp/esp-idf
  92. ./install.sh esp32,esp32s2
  93. or with Fish shell
  94. .. code-block:: fish
  95. cd ~/esp/esp-idf
  96. ./install.fish esp32,esp32s2
  97. In order to install tools for all supported targets please run the following command:
  98. .. code-block:: bash
  99. cd ~/esp/esp-idf
  100. ./install.sh all
  101. or with Fish shell
  102. .. code-block:: fish
  103. cd ~/esp/esp-idf
  104. ./install.fish all
  105. .. note::
  106. For macOS users, if an error like this is shown during any step::
  107. <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:xxx)
  108. You may run ``Install Certificates.command`` in the Python folder of your computer to install certificates. For details, see `Download Error While Installing ESP-IDF Tools <https://github.com/espressif/esp-idf/issues/4775>`_.
  109. Alternative File Downloads
  110. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  111. The tools installer downloads a number of files attached to GitHub Releases. If accessing GitHub is slow then it is possible to set an environment variable to prefer Espressif's download server for GitHub asset downloads.
  112. .. note:: This setting only controls individual tools downloaded from GitHub releases, it doesn't change the URLs used to access any Git repositories.
  113. To prefer the Espressif download server when installing tools, use the following sequence of commands when running ``install.sh``:
  114. .. code-block:: bash
  115. cd ~/esp/esp-idf
  116. export IDF_GITHUB_ASSETS="dl.espressif.com/github_assets"
  117. ./install.sh
  118. Customizing the tools installation path
  119. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  120. The scripts introduced in this step install compilation tools required by ESP-IDF inside the user home directory: ``$HOME/.espressif`` on Linux. If you wish to install the tools into a different directory, set the environment variable ``IDF_TOOLS_PATH`` before running the installation scripts. Make sure that your user account has sufficient permissions to read and write this path.
  121. If changing the ``IDF_TOOLS_PATH``, make sure it is set to the same value every time the Install script (``install.bat``, ``install.ps1`` or ``install.sh``) and an Export script (``export.bat``, ``export.ps1`` or ``export.sh``) are executed.
  122. .. _get-started-set-up-env:
  123. Step 4. Set up the environment variables
  124. ========================================
  125. The installed tools are not yet added to the PATH environment variable. To make the tools usable from the command line, some environment variables must be set. ESP-IDF provides another script which does that.
  126. In the terminal where you are going to use ESP-IDF, run:
  127. .. code-block:: bash
  128. . $HOME/esp/esp-idf/export.sh
  129. or for fish (supported only since fish version 3.0.0):
  130. .. code-block:: bash
  131. . $HOME/esp/esp-idf/export.fish
  132. Note the space between the leading dot and the path!
  133. If you plan to use esp-idf frequently, you can create an alias for executing ``export.sh``:
  134. 1. Copy and paste the following command to your shell's profile (``.profile``, ``.bashrc``, ``.zprofile``, etc.)
  135. .. code-block:: bash
  136. alias get_idf='. $HOME/esp/esp-idf/export.sh'
  137. 2. Refresh the configuration by restarting the terminal session or by running ``source [path to profile]``, for example, ``source ~/.bashrc``.
  138. Now you can run ``get_idf`` to set up or refresh the esp-idf environment in any terminal session.
  139. Technically, you can add ``export.sh`` to your shell's profile directly; however, it is not recommended. Doing so activates IDF virtual environment in every terminal session (including those where IDF is not needed), defeating the purpose of the virtual environment and likely affecting other software.
  140. .. _get-started-start-a-project:
  141. .. _get-started-build:
  142. .. _get-started-configure:
  143. .. _get-started-connect:
  144. .. _get-started-linux-macos-first-steps:
  145. Step 5. First Steps on ESP-IDF
  146. ==============================
  147. .. include:: linux-macos-start-project.rst
  148. .. include:: start-project.rst
  149. Tip: Updating ESP-IDF
  150. ======================
  151. It is recommended to update ESP-IDF from time to time, as newer versions fix bugs and/or provide new features. Please note that each ESP-IDF major and minor release version has an associated support period, and when one release branch is approaching end of life (EOL), all users are encouraged to upgrade their projects to more recent ESP-IDF releases, to find out more about support periods, see :doc:`ESP-IDF Versions <../versions>`.
  152. The simplest way to do the update is to delete the existing ``esp-idf`` folder and clone it again, as if performing the initial installation described in :ref:`get-started-get-esp-idf`.
  153. Another solution is to update only what has changed. :ref:`The update procedure depends on the version of ESP-IDF you are using <updating>`.
  154. After updating ESP-IDF, execute the Install script again, in case the new ESP-IDF version requires different versions of tools. See instructions at :ref:`get-started-set-up-tools`.
  155. Once the new tools are installed, update the environment using the Export script. See instructions at :ref:`get-started-set-up-env`.
  156. Related Documents
  157. =================
  158. * :doc:`establish-serial-connection`
  159. * `Eclipse Plugin <https://github.com/espressif/idf-eclipse-plugin/blob/master/README.md>`_
  160. * `VSCode Extension <https://github.com/espressif/vscode-esp-idf-extension/blob/master/docs/tutorial/install.md>`_
  161. * :doc:`../api-guides/tools/idf-monitor`
  162. .. toctree::
  163. :hidden:
  164. :maxdepth: 1
  165. establish-serial-connection
  166. flashing-troubleshooting
  167. ../api-guides/tools/idf-monitor
  168. .. _AUR: https://wiki.archlinux.org/index.php/Arch_User_Repository
  169. .. _First Steps on ESP-IDF: ../get-started/first-steps.html
  170. .. _cmake: https://cmake.org/
  171. .. _ninja: https://ninja-build.org/
  172. .. _ccache: https://ccache.dev/
  173. .. _homebrew: https://brew.sh/
  174. .. _MacPorts: https://www.macports.org/install.php
  175. .. _Catalina 10.15 release notes: https://developer.apple.com/documentation/macos-release-notes/macos-catalina-10_15-release-notes