A linear motor works on the same principles as a regular motor -- using electricity and magnetism to produce physical movement. The big difference is that a linear motor propels something in a straight line instead or rotating a shaft. Linear motors are used to propel vehicles like trains, monorails and amusement park rides that run along a rail. When linear motors are used like guns to propel an object, they are called linear accelerators. Linear motors have many proposed future uses and currently they make interesting science fair projects.
Build a track. Under the track are a set of magnets placed so the poles that are facing up alternate between North (N) and South (S). As the vehicle runs along the track it will encounter N and S poles alternately. The magnets under the track will be driving the vehicle. Along the track there will be two wires on the surface that the vehicle runs on. Between each magnet, the wires drop down beneath the track and cross over -- so the wire that was on the left track is now on the right track and vice versa. This crossing over is going to make the electromagnet in the vehicle change polarity as it runs along the track. Attach the wires at the beginning of the track to the poles of the battery.
Make the vehicle that will run on the track. The only essential component of the vehicle is the electromagnet. You can buy these in any hobby shop. If you cannot find one that fits your vehicle, you can make one by wrapping a few feet of enameled copper wire around an iron core. You should try to get the end of the electromagnet as close to the under-track magnets as possible. The core of the electromagnet can protrude beyond the bottom of the vehicle. One wire of the electromagnet should attach to the left side of the vehicle -- so it will be in electrical contact with the wire on the left side of the track. The other wire of the electromagnet should attach to the right side of the vehicle -- so it will be in electrical contact with the wire on right side of the track.
Test your linear motor and fine tune it for better performance. The electromagnet should switch polarity when it is over the magnet that will repel it, then the forward motion will push it toward the next magnet which will attract it while the previous magnet repels it. Fine tuning for performance involves experimenting with the distance between magnets and the places where the wires cross over.
Using rollers where the vehicle meets the track will reduce friction, but it might take some searching to find rollers that conduct electricity.
Constantly running your linear motor will damage the vehicle unless you use a little forethought in designing your motor. A good and safe way to design the motor is to extend the track past the alternating magnets and have a cushioned wall at the end of the track to stop the vehicle.