Install ESP32 ESP-IDF on Linux Ubuntu

This is a step-by-step tutorial, which will show you how to install ESP32 ESP-IDF in Linux Ubuntu and then build and flash an example code to an ESP32 development board. The official IoT Development Framework for the ESP32, ESP32-S, and ESP32-C line of SoCs is known as ESP-IDF. It offers an independent SDK for creating any type of generic application on various platforms using C and C++ programming languages.

We have a similar guide for Windows operating system:

Install Pre-requisites for ESP-IDF installation on Linux (Git)

The first step for installing ESP-IDF in our Linux Ubuntu system, is to fulfill all the necessary pre-requisites for the successful installation. We will first start by installing Git in our system. Open the following link: (https://git-scm.com/). The following web page will open:

Click “Downloads” highlighted below to select the download version according to your operating system.

Install Git for Linux Ubuntu machine 1

In the Downloads page, click ‘Linux/Unix‘ as your operating system.

Install Git for Linux Ubuntu machine 2

Here you can view the command that is required to get Git on our system. It is highlighted below:

Install Git for Linux Ubuntu machine 3

Open the Terminal in your Linux Ubuntu system and write down the following command:

apt-get install git

You will be asked for your password. After entering the password, the Git will start installing on the system.

Install Git for Linux Ubuntu machine Terminal 1

After a few moments, Git will get installed. Type the following command in the terminal to ensure the successful installation of Git on your system.

git --version

As you can see the in the picture below, the output shows that git version 2.34.1 in present in our system. Hence, all is well. Let us move to the next step.

Install Git for Linux Ubuntu machine Terminal 2

Install ESP-IDF on Linux Ubuntu

Open the official ESP-IDF documentation. Open the following link: (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/index.html). This opens the official ESP32 getting started webpage by Espressif. Scroll down until you reach the Manual Installation section. Here click ‘Linux and macOS.’

Install Prerequisites for starndard toolchain setup for Linux 1

This will open the Standard Setup of Toolchain for Linux and macOS webpage. This webpage provides a detailed step by step method to install ESP-IDF. We will follow it.

Step 1 Install Prerequisites for Standard Toolchain Setup (Linux)

The first step here is to install all the necessary pre-requites. Copy the command for Ubuntu setup and paste it in the Terminal. This will install all the pre-requites with Python that are required.

Install Prerequisites for starndard toolchain setup for Linux 2
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
Install Prerequisites for starndard toolchain setup for Linux 3

Here is how the output looks like after the process completes.

Install Prerequisites for starndard toolchain setup for Linux 4

Permission issues/dev/ttyUSB0

There is a common issue where the currently logged user does not have read and write access to the serial port over USB. To enable that, scroll down until you reach the following section of ‘Permission issues/dev/ttyUSB0‘. Click the link highlighted below to find the solution.

Install Prerequisites for starndard toolchain setup for Linux 5

This link opens the page where there is information regarding establishing serial connection with ESP32 and PC. The command highlighted below is used to add the user to dialout on Linux.

Install Prerequisites for starndard toolchain setup for Linux 6

Copy this command and paste it in the Terminal. Press enter. This will grant permission to the user to access the serial port.

sudo usermod -a -G dialout $USER

Now re-login to your PC to enable the changes to take place.

Install Prerequisites for standard toolchain setup for Linux 7

Step 2: Get ESP-IDF

After fulfilling the prerequisites, let us move to the next step.

Install ESP-IDF for starndard toolchain setup for Linux 1

Copy the following commands to the Terminal. Here we will first create a directory called ‘esp.’ Then we will navigate in that directory and do a git clone.

mkdir -p ~/esp
cd ~/esp
git clone --recursive https://github.com/espressif/esp-idf.git
Install ESP-IDF for starndard toolchain setup for Linux 2

Here is how the output looks like after the process completes.

Install ESP-IDF for starndard toolchain setup for Linux 3

Step 3: Set up the Tools

Now we are all ready to build the toolchain. Run the following command in the terminal.

Get the tools for standard toolchain setup for Linux 1
cd ~/esp/esp-idf
./install.sh esp32
Get the tools for standard toolchain setup for Linux 2

This is how the output looks like when the process completes. We have successfully installed the toolchain.

Get the tools for standard toolchain setup for Linux 3

The next step is to import the environment variables that are required. Type the following command in the Terminal and press enter. This will enable the tools to be from the command line by setting some environment variables.

. ./export.sh

This is the output we obtain after the command is run. Here you can view that all the environment variables that we need have been loaded and it is ready to compile ESP-IDF projects.

Get the tools for standard toolchain setup for Linux 4

Let us first look at this directory. Type the following command in theTerminal:

ls -al

You can find the examples directory present here

First Example Project ESP-IDF 1

Opening the examples directory, we can see that there are various basic examples provided listed below.

cd examples/
ls -al
First Example Project ESP-IDF 2

Let us open the get-started folder. Here you can view the hello_world example. Lets try to build that.

First Example Project ESP-IDF 5

Build Hello World Example Sketch

To build the hello_world example project, first head over to the ~/esp directory as highlighted in the red box below. Then copy the hello_world project to that directory.

cd ~/esp
cp -r $IDF_PATH/examples/get-started/hello_world .
First Example Project ESP-IDF 6

Enter the commands in the Terminal shown in the picture below, to build the hello_world project.

To build a project, use idf.py build command. This command will compile the application and all ESP-IDF components. Additionally it will also generate the bootloader, partition table, and application binaries.

idf.py build
First Example Project ESP-IDF 3

This is how the output looks like showing a successful project build. We are now ready to flash our chip.

First Example Project ESP-IDF 4

Where to go next?

Leave a Comment