Install ESP-IDF and Build Your First Project With idf.py
Install ESP-IDF v5.4 on Linux or macOS, source export.sh, build the hello_world example with idf.py and flash it to an ESP32 board over USB.

The first hour with an ESP32 usually goes to the toolchain, not to the code. ESP-IDF is not a package you install with one command: it is a Git checkout, a script that downloads compilers into your home directory, and a second script you must run in every terminal before anything works. When a step is missed, the errors read as "command not found" or "permission denied", which tells a beginner nothing about the cause. This post walks the whole path once with ESP-IDF v5.4: prerequisites, installation, the export step, building the hello_world example, flashing it, reading the monitor, and the two fixes that unblock most failed first attempts.
It assumes an ESP32 development board with a USB cable that carries data. A charge-only cable is the most common reason a board never shows up as a serial device, and it is worth testing with a different cable before you change anything else.
Install the prerequisites
ESP-IDF needs Git, Python 3.9 or newer with venv and pip, CMake 3.16 or newer, and Ninja. It also uses ccache to speed up rebuilds and dfu-util for boards that flash through USB DFU. The package names differ by system.
On Debian and Ubuntu:
sudo apt-get update
sudo apt-get install git wget flex bison gperf python3 python3-pip python3-venv \
cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0On macOS with Homebrew:
brew install cmake ninja dfu-util ccache python3On Windows, skip all of this and use the ESP-IDF Tools Installer from Espressif, which installs the same pieces and creates a pre-configured "ESP-IDF" command prompt and PowerShell shortcut. The rest of the post uses the Linux and macOS commands, and the idf.py commands are identical on Windows once the environment is active.
Clone ESP-IDF and install the tools
Choose a directory for the framework. ~/esp is the convention in Espressif's documentation, but any path without spaces works. Clone the release branch for the version you want, with submodules, because the Wi-Fi and Bluetooth libraries and many components are submodules:
mkdir -p ~/esp
cd ~/esp
git clone -b v5.4 --recursive https://github.com/espressif/esp-idf.gitThe clone is large, several hundred megabytes with submodules, so expect it to take a few minutes. Then run the installer from inside the checkout. It takes a comma-separated list of chip targets so you download only the compilers you need:
cd ~/esp/esp-idf
./install.sh esp32,esp32s3install.sh creates a Python virtual environment under ~/.espressif, installs the Python packages ESP-IDF needs, and downloads the Xtensa and RISC-V cross compilers, OpenOCD and other tools to the same place. Nothing is installed system-wide, which means you can delete ~/.espressif to start over and you can have several ESP-IDF versions side by side.
Source the export script in every terminal
This is the step people forget. install.sh does not change your PATH or set IDF_PATH. A script called export.sh does that, for the current shell only, and it must be sourced rather than executed, because a child process cannot change its parent's environment:
. ~/esp/esp-idf/export.shIf you run it as ./export.sh, it exits without effect. After sourcing it correctly, check that the command exists and reports the version:
idf.py --versionESP-IDF v5.4Because you will do this in every new terminal, add an alias to ~/.zshrc or ~/.bashrc:
alias get_idf='. $HOME/esp/esp-idf/export.sh'Do not source export.sh from your profile on every login: it takes a moment to check the environment and it puts the ESP-IDF tools on your PATH for every shell, including ones where they conflict with other toolchains. Typing get_idf when you want to work on firmware is a good trade.
Copy the hello_world example
ESP-IDF ships many examples under examples/. Copy one out of the framework tree rather than building in place, so that your changes do not live inside the Git checkout:
mkdir -p ~/esp/projects
cp -r $IDF_PATH/examples/get-started/hello_world ~/esp/projects/
cd ~/esp/projects/hello_worldThe directory has the layout of every ESP-IDF project: a top-level CMakeLists.txt, a main folder with its own CMakeLists.txt and the source file hello_world_main.c, and a README. If you would rather start from an empty project, idf.py create-project hello --path ~/esp/projects generates the same skeleton.
Choose the chip target
A project builds for one chip at a time, and the default is the original ESP32. To build for another chip, set the target once. The command wipes the existing build directory and the sdkconfig file, because the options for one chip are not valid for another:
idf.py set-target esp32s3Adding "set-target"'s dependency "fullclean" to list of commands with default set of options.
Executing action: fullclean
Executing action: set-target
Set Target to: esp32s3, new sdkconfig will be created.
...
-- Configuring done
-- Generating doneIf you are not sure which chip is on your board, the silkscreen on the module shield names it, such as ESP32-S3-WROOM-1 or ESP32-WROOM-32. A mismatch is not dangerous, but flashing an image built for the wrong chip fails with a chip-ID error from the tool.
Build
idf.py buildThe first build compiles the whole of ESP-IDF's required components, around a thousand files for a small project, and takes a few minutes. Later builds recompile only what changed. It ends with a size summary and the flash command:
Project build complete. To flash, run:
idf.py flash
or
idf.py -p PORT flashA build can fail for reasons that are really about the environment, not your code. If it says that CMake is too old, or that a Python module is missing, you probably built in a terminal where export.sh was not sourced, or after upgrading the system Python; re-run ./install.sh to rebuild the virtual environment.
Find the serial port
Connect the board. The port name depends on the system and on the board's USB interface. On Linux, a board with a CP210x or CH340 bridge appears as /dev/ttyUSB0, and a board using the chip's own USB, such as many ESP32-S3 boards on the USB connector marked "USB", appears as /dev/ttyACM0. List the candidates:
ls /dev/ttyUSB* /dev/ttyACM*/dev/ttyACM0On macOS, look for /dev/cu.usbserial-* or /dev/cu.usbmodem*. On Windows, open Device Manager and read the COM port number under "Ports".
On Linux, opening the port can fail with a permission error, because the device node belongs to the dialout group on Debian-based systems (uucp on Arch). Add yourself to the group and log out and back in:
sudo usermod -a -G dialout $USERA fatal error occurred: Could not open /dev/ttyACM0, the port doesn't existor, before the group change:
serial.serialutil.SerialException: [Errno 13] could not open port /dev/ttyACM0: [Errno 13] Permission denied: '/dev/ttyACM0'The first message, "the port doesn't exist", means the port name is wrong or the board is not enumerating, which points to a charge-only cable or a board that needs the other USB connector. The second is the permission problem the group fixes.
Flash and monitor
Flash the three binaries, bootloader, partition table and application, and open the serial monitor in one command:
idf.py -p /dev/ttyACM0 flash monitorflash runs esptool, which resets the chip into its ROM bootloader, uploads the images and resets again. The output shows the chip type, the MAC address and the progress of each region:
esptool.py v4.8.1
Serial port /dev/ttyACM0
Connecting....
Chip is ESP32-S3 (QFN56) (revision v0.2)
Features: WiFi, BLE, Embedded PSRAM 8MB (AP_3v3)
Crystal is 40MHz
...
Writing at 0x00010000... (100 %)
Wrote 187136 bytes (101234 compressed) at 0x00010000 in 2.3 seconds
Hash of data verified.
Leaving...
Hard resetting via RTS pin...The speeds, sizes and tool version will differ on your machine. After the reset, the monitor shows the boot log from the ROM bootloader, the second-stage bootloader and then the application. The hello_world example prints chip information and restarts every ten seconds:
I (341) main_task: Calling app_main()
Hello world!
This is esp32s3 chip with 2 CPU core(s), WiFi/BLE, silicon revision v0.2, 2MB external flash
Minimum free heap size: 389556 bytes
Restarting in 10 seconds...Exit the monitor with Ctrl+]. If you use Ctrl+T followed by H, the monitor prints its own command list, including reset and flash shortcuts, so you can rebuild and reflash without leaving it with Ctrl+T then A.
The commands you will use daily
Four commands cover most of a working day, and a few more are worth knowing by name:
| Command | What it does |
|---|---|
idf.py build | Compile what changed |
idf.py -p PORT flash | Write bootloader, partition table and app |
idf.py -p PORT monitor | Serial console with address decoding |
idf.py menuconfig | Edit the configuration |
idf.py fullclean | Delete the build directory completely |
idf.py size | Print flash and RAM use of the image |
idf.py erase-flash | Erase the whole flash, including NVS |
You can chain commands in order, as in idf.py build flash monitor, and set the port once with the ESPPORT environment variable so that you stop typing -p.
When the flash step cannot connect
If esptool prints Connecting......_____...... and then fails with "Failed to connect to ESP32: No serial data received" or "Wrong boot mode detected", the chip did not enter download mode. Most development boards do this automatically through two USB-serial control lines wired to the reset and boot pins. Boards without that circuit need a manual sequence: hold the BOOT button, press and release RESET, then release BOOT and run the flash command again. A separate post covers both the manual sequence and the auto-reset circuit.
What to do next
With the loop working, change something visible: edit the string in hello_world_main.c, run idf.py build flash monitor, and watch the new text appear. Then open idf.py menuconfig and look at the top-level menus once, so you know where the options live: "Serial flasher config" for the flash size, "Partition Table", and "Component config" for FreeRTOS, Wi-Fi and logging. The guide on this site that covers the whole ESP32 workflow builds on exactly this setup.


