While arduino-cli is an awesome tool, unfortunately most guides skip right past it and assume you use the Arduino IDE, this page is a collection of common patterns for arduino-cli. It assumes that you know a few things about how Arduino works.


To create a sketch arduino-cli assumes that your main .ino file has the same name as the directory containing it.

To build and upload use arduino-cli compile --fqbn <fqbn> and arduino-cli upload -p <serial-device> --fqbn <fqbn> in your code directory.

Hint: On Linux your serial devices are called /dev/ttyUSBn and /dev/ttyACMn where n is a number. Make sure you have the permissions to access them and nothing else is trying to use those ports.

FQBN? Fully Qualified Board Name!

The Fully qualified Board name consists of what Arduino calls the Platform ID and a name for the board. You can find it out either by using arduino-cli board search <searchterm>, arduino-cli board listall or by appending the official board name in lowercase to the Platform ID.

Examples include:

Please note that the esp boards are not available by default.

Compile and Upload a Sketch using arduino-cli

I usually create a script to make development and testing easier.

arduino-cli compile --fqbn arduino:avr:uno && \
arduino-cli upload --fqbn arduino:avr:uno -p "${1:-/dev/ttyUSB0}"
A simple compile and upload script with a fixed board and an optional argument for the serial port that defaults to /dev/ttyUSB0

Note: When given the -u flag and the options needed for uploading arduino-cli compile --fqbn arduino:avr:uno -u -p "${1:-/dev/ttyUSB0}" behaves like the above example script.

Note on shell syntax: The "${1:-/dev/ttyUSB0}" is read by your shell as replace this with the first argument given to the script or with /dev/ttyUSB0.

Adding more Boards

The arduino-cli is not just a wrapper for a compiler and whatever you prefer for uploading … it also is a package manager. If you want more boards (or libraries) you can search for and install them.

But if you want to write code for a non-Arduino branded board (i.e. an ESP8266 or ESP32) those packages are not in the Arduino package repositories.

Adding an extra repository can be done by letting arduino-cli do the work …

arduino-cli config add board_manager.additional_urls 'url://to/index.json'

… or by manually editing ~/.arduino15/arduino-cli.yaml and adding the URL pinting to the respositories *_index.json file there.

An excerpt from the configuration file from my laptop with additional URL to the stable esp8266 and esp32 repositories in addition to the development version of the esp32 repository.

Don't forget to arduino-cli update and arduino-cli upgrade!

Flashing a Bootloader using arduino-cli

arduino-cli already knows how to flash a new bootloader with the burn-bootloader subcommand, you have to tell it for which board you want the bootloader using --fqbn and which programmer you are using with -P.

Note: Programmers usually aren't quite cheap, but if you have another Arduino (compatible) with UART (serial) and SPI interface you can use that Arduino as an ISP . (use -P arduinoasisp)

It may be necessary to provide the port the programmer is on via the -p option. (like with the upload command)

Example using the official AVRISP mkII programmer for AVR chips for an ATMEL 328P in an Arduino Uno like configuration
arduino-cli burn-bootloader --fqbn arduino:avr:uno -P avrispmkii

To find out which programmer string you need, go to the ArduinoCore-* repository of your favourite architecture (See for the official ones) and open the programmers.txt file (i.e. ArduinoCore-avr/programmers.txt), the keys used there are the needed ids for the -P option.

Why do I need a Bootloader?

To be able to seamlessly upload code with just a USB to serial converter like in the example above your microcontroller needs to have the Arduino bootloader installed, a small piece of software that runs when the controller starts (that's the reason you need to hook up the reset line when programming) that can be told to write a new program to the controller instead of starting the already existing one.

The boards you can buy online come with a bootloader preinstalled. But maybe you want to build your own Arduino compatible or released the magic smoke and want to just buy the chip itself without a development-board, that is when you want to flash the bootloader yourself.

Do I need a Bootloader to use the Arduino Framwork?

No, you can use the programmer of your choice (just use the -P option with the upload command) to flash whatever yo coded up directly into the controller at the cost of having to use the programmer every time you upload a new program. (Unless that program is a bootloader 😉)

You may also be interested in

The official arduino-cli documantation

Serial Port Troublehooting on Linux