Physical contact is a "touchy" subject for some people. Not everyone appreciates being in close proximity with others and hugs can be very unconformable and uninviting. Flat-out refusing a hug from someone, on the other hand, can result in hurt feelings and overall negativity. If you're around someone who likes to give unwanted hugs, avoiding that situation can make your social interactions with the person more enjoyable.
Take a step back when the person first approaches you. While subtle, this creation of distance will often signal to the other person that a hug is not preferred and no further action is needed.
Offer your hand in a handshake. The handshake can be used as a substitute for a hug and if you do this enough, the person could get the hint that you don't prefer hugs.
Position yourself so a desk or another barrier remains between you and the other person that prevents them from invading your personal space.
Say that you have a cold. While this won't work on the same person all the time since it's unlikely you'd always be sick, the cold excuse inherently implies that a hug is not a good idea and over time, the other person will give up attempting an embrace.
Apologise and explain that you don't prefer hugs if the person continues to try hugging when you're in the same space. Explain that it's nothing personal and that you're just not a hugger. The other person should respect your views and not make a big deal of it.