Unfortunately you do pretty much have to learn them word by word. There are no 100% reliable rules but there are some useful rules of thumb that can help, for instance:
- Some word patterns tend to have a predictable gender. For example, nouns derived from a verb and ending -ung tend to be feminine, such as die Erzählung or die Entschuldigung. But beware other -ung words like der Schwung.
- Diminutives (ending -chen or -lein) are almost always neuter (das Mädchen, das Fräulein, etc.) even when (as in both of those cases) the meaning might lead us to expect a feminine noun.
- Words adopted from other languages tend to adopt the gender of their native German synonym. So you sometimes see das Girl, the same neuter gender as das Mädchen. One of my favourites is Single: die Single is a 9" vinyl record (like die Platte), der Single is an unmarried man, and das Single is a singles match (e.g. in tennis, like das Spiel).
I'm sure other people can add other helpful guidelines below.
I always compare this to pronunciation in English. In German, pronunciation is phonetic and very preditable (e.g. -au- is always preferred the same way) whereas in English it's very unpredictable and has to be learnt word by word (cough, though, through, bought, etc.). The flip side is that in English we don't have grammatical gender and our word for 'the' is very simple (it's 'the' :), whereas in German the gender has to be learn by rote. You regularly hear small German children being corrected on their noun genders in just the same way English-speaking kids have their pronunciation corrected.