Compiling code via terminal
Assuming an AVR-based Arduino, you would need the avr-gcc compiler, the
avr-libc and the Arduino libraries. Also avrdude if you want to upload.
The only issue is that the commands used for the build process are quite
long (lots of options). You can see them by enabling verbose compilation
in the IDE. Thus you will probably want some way to automate the whole
thing.

There are several options for this. The most straightforward seems to be
the arduino-builder command-line tool. This is part of the Arduino
project and should ensure maximum compatibility. Otherwise you could use
a plain old Makefile. I personally use Sudar Muthu' Makefile. It can
be installed on a Debian-based Linux distribution by:

sudo apt install arduino-mk


It is not fully compatible with the classic Arduino build process
though: it does automatically include &lt;Arduino.h&gt; into your sketch,
but it does not add forward declarations. Some prefer it this way, as
the automatic inclusion of forward declarations is somewhat buggy and
does not play well with some C++ features.