To build applications for the ESP32, you need the ESP-IDF software libraries provided by Espressif. Consult ESP-IDF Versions for information about which ESP-IDF version to use in a given situation. To get ESP-IDF, navigate to your installation directory and clone the repository with git clone, following instructions:
cd ~/development/esp32 # This will clone the Master Branch git clone --recursive https://github.com/espressif/esp-idf.git # This will clone a stable release. Assuming that 4.0 is the latest stable release git clone -b v4.0 --recursive https://github.com/espressif/esp-idf.git
ESP-IDF will be downloaded into ~/esp/development/esp32/esp-idf.
Aside from the ESP-IDF, you also need to install the tools used by ESP-IDF, such as the compiler, debugger, Python packages, etc. The scripts below installs the 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. If changing the IDF_TOOLS_PATH, make sure it is set to the same value every time the Install script (install.sh) and an Export script (export.sh) are executed.
cd ~/development/esp32/esp-idf ./install.sh
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. In the terminal where you are going to use ESP-IDF, run:
. $HOME/esp/esp-idf/export.sh
Note the space between the leading dot and the path!
You can also automate this step, making ESP-IDF tools available in every terminal, by adding this line to your .profile or .bash_profile script.