From version 1.5.0 ,Arduino has its own official CLI, see https://github.com/arduino/Arduino/blob/master/build/shared/manpage.adoc.
PlatformIO is an open source ecosystem for IoT development with cross platform build system and library manager. (A free account is required if you would like to use it to run more advanced features like unit tests.)
// Restored the following text from history ~~TimPe, 2011-07-13
Here is a Makefile for compiling and uploading Arduino programs from the command line without the use of the Arduino environment or Java. You will still need a number of other programs. On the Mac or Windows, it's probably easiest just to download and install the Arduino software. Then grab this makefile: Attach:Makefile
On Linux, you will need to install avr-gcc (whose package is usually called gcc-avr), avr-libc and avrdude. On Debian you might try
sudo apt-get install gcc-avr avr-libc avrdude
On Gentoo, see the instructions, but don't worry about installing Java, RXTX, subversion, or jikes or checking anything out of subversion, but do substitute avrdude for uisp. Then, download this zip archive of the Arduino core (it includes the Makefile): Attach:arduino-core-0005.zip
Instructions for writing, compiling/verifying, and uploading your programs are in the Makefile.
Minor detail: on my OS X 10.4 box, I had to add a "-C /location/to/avrdude.conf" to AVRDUDE_FLAGS otherwise it's bombing out when avrdude wants to upload your code.