Your first, best option as in any fight: beat feet out of there. If that's not a good option:
1) The best time to make a move is when the guy goes for the knife. Chances are he has to reach inside something (pocket, belt scabbard, boot) to retrieve it. If you see someone reaching for something, bum rush them and take them out. At the very lease rush in and shove them down; if he reaches again, that's your clue that this guy is packing *something* he wants to bring to bear, and you should beat him mercilessly.
2) Once it's out: if you can, grab an improvised weapon.
-- Anything that can be used as a club, especially if it gives you range, is preferable to a knife. If you're in a bar near a pool table, grab a cue. If you have time and it's a two-piece, unscrew it and use the thick butt end; if not, still try to use the butt end to strike, slash or jab with the thin end.
-- A bar stool held on the seat end and used as a parry weapon (think of a lion tamer) is great; you can block the knife hand and/or shove the legs into him (if you can trap the knife hand) and shove him off balance.
-- If you have a belt, get it off pronto, wrap the end with the holes in your hand once or twice, and use it like a flail, striking with the buckle. Keep it swinging at a lazy, circular arc next to your body, whip it hard when they move, striking with the buckle. It's a simple, time-tested, old-school dirty brawling/gang-fighting tactic that will split the skin on an opponents' head wide open if it hits his skull and will hurt like a sumbitch everywhere else..
If you know how, you can block slashes with the belt (holding an end in each hand) and/or use it to tie up the knife hand and eventually disable an opponent. Can't be explained, you just have to learn.
-- Pick up something, throw it, rush when he flinches and raises his hands to protect himself.
-- If you have only your mitts and feet to rely on: that depends on the size of the blade and type/direction of attack. Sidestep stabs, and for slashes, move in on the raising of the blade or the downswing and trap the arm. Even if you fail to get control, you're better off in close; stabs are bad, but slashes are worse. Slashes cause more nervous system shock, much worse bleeding, and incapacitation of muscles than stabs.
-- Remember the golden rule of knife defense: treat the knife as the extension of the arm. Defend accordingly.
-- Whether you attack empty-handed or bearing a weapon: incapacitate the knife hand. Hit it (or the forearm) with a club, slash it (or the forearn) with a cutting weapon, tie it up with a hold. If the knife hand is out of action, the knife is out of action, and your chances of getting away alive without major injury increases dramatically.
And train knife defense. Krav Maga, Judo, Jiu Jitsu (Brazilian or otherwise), Kali, and Hapkido all have an excellent repetoire of knife defenses.