Carry bear spray. Yes, there is a reason they sell this in stores near hiking trails that have bears. The capsaicin spray will create a cloud that usually stops a bear. Don't keep it in your backpack — have it where you can quickly use it.
Play dead if it's brown. As the graphic shows, lie down in a fetal position and then play dead. A grizzly bear, which is brown, will not perceive you as a threat or prey if you are not running. The fetal position will help protect you as much as possible if the bear should attack.
Fight back if it's black. A black bear typically wants nothing to do with you, but if you have startled it, it has cubs nearby, or it's extremely hungry, it will attack if you run or lie down. Grab rocks and sticks as weapons, yell, wave your arms and make yourself as large as you can. Hopefully, they'll run off like a squirrel would.
Don't climb a tree. They can climb them, too.