Quick ESP32 installation guide for linux

published:2025-02-24

updated:2025-02-24

tag:#Electronics #ESP32 #Linux

category:Tool

What is ESP32?

ESP32 is a series of low-cost & low-power SoC (system on a chip) microcontrollers created and developed by Espressif systems. In the ESP32 series we can find Single-Core and Dual-Core microprocessors that employ Xtensa and RISC-V architectures.

Most of the ESP32 series come with the built-in WiFi (802.11 b/g/n) and Bluetooth (v4.2 BR/EDR & BLE). The CPU runs a 32-bit microprocessor which operates at 160 Mhz to 240 Mhz.

It has built-in capacitive sensing, 12-bit ADC (Analog to Digital Converter), 8-bit DAC (Digital to Analog Converter), PWM (Pulse Width Modulation), SPI, I2C, I2S, UART, and many more.

What are the limitations of using Arduino for ESP32?

When you search for ESP32 tutorials, you will get bunch of tutorials around Arduino IDE and the Arduino library and the reason is the simplicity. While the Espressif has provided a very robust framework for the ESP32 series called IDF (IoT Development Framework), which has a steeper learning curve.

The problem with Arduino is that it’s designed to work with simpler microcontrollers such as Atmel which limits access to advanced ESP32 features.

For the simple or even for hobbyist projects, it’s completely fine to use Arduino framework, but if you think of a serious IoT project, the Arduino simply will be a blocker.

Also, using Arduino, forces you to use their IDE, which is extremely unproductive. With ESP-IDF, we are not limited to any specific IDE or text editor.

Install ESP-IDF on Linux for ESP32 development

For Debian-based Linux users, they’re a few packages that need to be installed before the ESP-IDF. such as git wget flex bison gperf python3 python3-pip python3-venv cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0

Dependency packages

$ 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-0

If you need to know more about each of these packages, you can run $ apt info <packageName> to get information about the package. But if you’re using Linux as your primary OS, you’re most likely to have most of these packages already installed.

ESP-IDF installation

Espressif has made the framework open-source and we can find it on their GitHub page at https://github.com/espressif/esp-idf. We have to clone this repository onto our system.

$ mkdir -p ~/esp
$ cd ~/esp
$ git clone -b v5.4 --recursive https://github.com/espressif/esp-idf.git
  • The -b flag tells the Git to clone a specific branch/tag, which is “v5.4”. Check out the version and release notes on Espressif website.
  • The --recursive flag ensures that all submodules within the repository are also cloned.

Once it’s downloaded, we can move to the ~/esp directory and we should see the esp-idf directory in it. Now we can run ./install.sh esp32 to complete the installation of ESP-IDF. The “install.sh” first parameter should be the name of the SoC that you’re using. If you’re using ESP32-S3 SoC, then the command must be ./install.sh esp32s3. Also, you can use multiple SoCs separated by commas. If you want to have all of the ESP32 series installed, use “all” as the parameter, but this will take a while to complete.

Setup environment variables

The installation is done but it’s not added to the PATH environment yet. Therefore, we cannot run it in on our project directory. In order to add it to the PATH we should run

$ . $HOME/esp/esp-idf/export.sh

In any terminal session that you want to use the IDF, you must run the export command. This is tedious if you are in heavy development. One way to make it easier is to create an alias in your profile.

alias get_idf='. $HOME/esp/esp-idf/export.sh'.

Now you can run get_idf on any session you wanna work in.

When you run the command, you will notice that you have to you use idf.py build in order to compile and build the project.

Project configuration

To test, we can copy one of the examples from the ESP directory.

$ mkdir my_project
$ cd my_project
$ cp -r $IDF_PATH/examples/get-started/hello_world/* .

Now we should set the target and get to the configuration menu.

$ get_idf
$ idf.py set-target esp32s3    # Required for every new target SoC
$ idf.py menuconfig

In the configuration menu, we can set WiFi password, Processor speed, etc. But for the Hello World application, we don’t need any configuration.

Compile, Monitor, and Deploy project on ESP32

Before going any further we must connect our ESP32 dev/custom board to the computer. When it’s connected we can verify it by running $ ls -a /dev/ttyUSB0. If the output is “cannot access”, it means that the board is not recognized by the OS. You need to check the cable or the board itself whether it’s still alive.

On some dev kits, such as “ESP32-S3 DevKitC-1U” we can see there are two micro-usb ports, labeled as “USB” and “UART”. If we connect it via USB port, we should look for the /dev/ttyACM0 port and if we connect it via UART, we should look for the /dev/ttyUSB0.

To compile the project, we can run $ idf.py build if there are no errors, the firmware binary (.bin) file will be generated in the “build” directory.

To deploy the binary onto the ESP32, we can then run $ idf.py -p <PORT_NAME> flash. The port name is either “ttyUSB0” or “ttyACM0”.

If the flashing operation has no errors we will see the output logs with “done” at the end.

To check whether the firmware is actually running we can monitor it using “monitor” command. If the program has any print output then you will see it on the terminal.

$ idf.py -p <PORT_NAME> monitor # change the PORT_NAME accordingly

The installation script

If you’ve made it until here, I would appreciate it if you could follow me on my Github page.

Every time you close the terminal session and open another one you have to go through those beginning steps which is tedious. To avoid this hassle of the installation for on a new system and development, I wrote a bash script to help with the installation and simplify the development process.

You can find the script on my Github.

The installation steps:

  1. Installing all dependencies
  2. Make “esp” directory in the $HOME directory
  3. Clone the ESP-IDF repository. If it’s already cloned, the script will simply skip this step
  4. Run & set up the ESP tools from the cloned repository
  5. Set IDF environment variable and create an alias in the shell’s session file

When running the script, you can set version, target & shell flags, run $ esp32-installer -h to see the flags’ descriptions. If no flags are set, the default values will be used.

And the last but not least, you can verify the installation by getting message below and/or run idf -p <port_name> build.

==============================
The installation has been completed
You can now use "$ idf -p <port_name> build" command
============================== 

Cheers!