Yes, a gun fired in space or on a space station or rocket ship should work as well as it would on Earth or possibly even better.
The laws of physics still apply in space. The path of the bullet should be fairly straight, as gravity is greatly reduced, though not entirely absent.
There may be a reduced air supply on a spaceship, and there would certainly be one outside it, so the bullet would encounter less friction and would probably continue on its path longer.
Newton’s third law, that for every action there is an equal and opposite reaction, means there would still be a recoil from the explosive expellation of the bullet.
As for the explosion that gets the bullet going, an old-fashioned six-shooter should still work very well, even in the relative absence of air. Gunpowder contains its own oxidizing agent, saltpeter, formally known as potassium nitrate, or KNO3.
Some problems present themselves for the shooter. If he is aboard a spaceship, a bullet hole could cause the loss of his own air supply; he should probably wait for a space walk.