A guy in Canada filmed himself being followed by a black bear.  And even though he stood his ground, shouted, and waved his arms like you’re supposed to, it kept coming.  So he used some bear spray, and it ran the other way.

He sprays it at 2:32 in the video. Bear spray can do the trick, but no bear deterrent is 100% successful.  Here are some guidelines.

And if all else fails, play your trombone.  It worked for this music teacher.  He plays it at 1:14.