It's hard to say when EXACTLY you should take the exam, because of the fact that different schools and programs have varying application deadlines. I'd recommend researching the programs you're interested in to see when their deadlines are.
Once you know the application deadlines, then you should aim to take your test at least a month before these deadlines (and 2 months if you want to leave room for a retake!). Scores take about 10-15 days to arrive at universities after you take the test.
For more information, read this article from our blog: When Should I Take the GRE?
Hope that helps!