Since sugar is made of only non-metals, it is a molecular compound with covalent bonds.
ionic compounds are generally composed of a metal and a non-metal*, which will form opposite ions and attract each other.
The dividing line between metals and non-metals is the "staircase":
Non-metals as ions would not bond with other non-metal ions, as they would both have negative charge and would repel.
And just to round out the explanation, it should be noted that metals will not bond with other metals, so there are no compounds made of only metals.
*With polyatomic ions, an ionic compound may consist of a metal and multiple non-metals. And there is one to watch out for: