You can use insecticide to kill them, but fungus gnats are usually a sign of a separate problem: the top layer of your medium is too wet for too long at a time. When you’re suffering from gnats, make sure you only water when the top inch of your medium is dry, and don’t drench it. With good watering practices, fungus gnats simply can’t reproduce and disappear.
You can also buy anti-gnat stickies to grab the little things. Turns out they can’t resist the colour yellow. 😀