If their body language indicates a need for distance, you should not try to hug them. However, if they look like they want to hug you and you feel comfortable offering a hug, go ahead and give them a hug.
[header] How to know if it is okay to hug someone [title] Observe their body language. [step] Look at whether their feet are pointed towards or away from you. See if they are leaning back and distancing themselves from your or leaning in towards you.