how to compile arduino sketch from termnial and then upload the firmware

I want to know how can I compile and upload the arduino sketch from my terminal instead of using Arduino IDE.

I want to use a different IDE for writing code then compile from terminal and upload.

Do a search for Arduino makefile. I have no experience with the Arduino specifics but it should get you on the right track.

The Arduino IDE has a command line interface (CLI):

There is a new official command line only tool called arduino-cli:

That is still in beta so you might run into some occasional problems, but beta testers are welcome.

The Arduino IDE also allows you to set it to use an external editor (File > Preferences > Use external editor). The Arduino IDE's text editor will be disabled and it will pick up any changes made to the file externally. This way, you can use the Arduino IDE only for compilation and upload and your favorite editor/IDE for writing the code.

pert:
The Arduino IDE has a command line interface (CLI):
Arduino/build/shared/manpage.adoc at master · arduino/Arduino · GitHub

There is a new official command line only tool called arduino-cli:
GitHub - arduino/arduino-cli: Arduino command line tool
That is still in beta so you might run into some occasional problems, but beta testers are welcome.

The Arduino IDE also allows you to set it to use an external editor (File > Preferences > Use external editor). The Arduino IDE's text editor will be disabled and it will pick up any changes made to the file externally. This way, you can use the Arduino IDE only for compilation and upload and your favorite editor/IDE for writing the code.

so the new arduino cli allows compiling the hex code to binary and upload as well ?

seaurchin:
so the new arduino cli allows compiling the hex code to binary and upload as well ?

You don't compile hex code, you compile source code; the result is a hex-file (in the Arduino environment). You can convert it to binary if you feel like that (not sure if its part of the cli, I haven't played with that) but I don't know if it's useful.

You can use arduino-cli to upload, just like how the Arduino IDE does it. You can find details here:

In the near future, the Arduino IDE is going to use arduino-cli for installing hardware packages, installing libraries, compiling, uploading. At that point, the IDE will only be a graphical interface for the arduino-cli. So arduino-cli will do anything the Arduino IDE can do, and more. This is something Arduino has been working towards for years. It used to be that everything was crammed into the IDE's Java code but they've gradually been moving it out into separate tools. That's extremely helpful for people like you who want to use a different IDE or not use an IDE at all.