Wherever possible, don't do it alone. At best, pair up with a friend or group to get one another home, and at worst, always have location-sharing on on Whatsapp. Make voice-noting your friends when you get home a habit among your group so everyone expects it and will check in if it doesn't happen – and have it be a voice note, not a text.
Walk like you're totally confident: make it clear that you know where you're going and you're aware of your surroundings. Look men (briefly) in the eyes as they pass so they know you've seen them and you're not scared.
Stay under streetlights and pass beside shops that are likely to have CCTV.
If anything happens, remember that a sudden, strong exhalation is the best way to bypass the 'freeze' response in your nervous system – which can be a big out-breath, or a shout or scream.
Do not be afraid to make noise, get big and act as crazy as you can. Of course fighting back always carries a risk, but the best thing you can do is be more trouble than you're worth.