The first reel that told some kind of a story ever made in the United States of America was Edwin S. Porter's The Great Train Robbery. It set a template for many movies to follow : crime, pursuit and retribution. Although it was filmed in New Jersey, the genre it spawned would come to be known as Western ; For the next sixty years, this genre would be one of the main staples of the Hollywood studios, and of movie theatres in America and the rest of the world.
Films belonging to this genre told the story of cowboys, gunfighters, immigrants, farmers, indians, soldiers and gamblers in the lawless territories beyond the Mississippi, were wrongs were righted with the help of the gun rather than the book of law. It was the American frontier of the nineteenth century. The country was too big for the men, who slowly filled it up ; and they could only rely upon themselves, alone in the wild or few in a small town. One knew what Good and Evil were. The frontier the movies told of was a myth ; the myth that founded much of modern day America.
Hollywood's west may have been mythical, but the true west wasn't far away. Many of the horseriders that would enact the special effects of the early westerns were cowboys in the 1880's ; as an example, John Ford, before becoming a major director of westerns, met Wyatt Earp, of whom he would tell the story thirty years later.
During the era of silent film, western was one of the mainstream genres in Hollywood, along with slapstick comedy. They were both "A movies", expensive, with an "intelligent" script and lavish production, and "B movies", quickly made, with a simpler scenario, more action, often in the form of long series with recurrent criminal-chasing heroes.
With the advent of sound, western lost its mainstream aspect, mainly because of the expensive failure of Raoul Walsh's The Big Trail, which starred John Wayne, in 1930 ; for the next decade, westerns would be B Movies, often featuring a popular singing cowboy.
In 1939, with John Ford's Stagecoach, and a few other movies, western again became a prestigious genre (although B level westerns didn't disappear). John Wayne was the star of the era, which is what people usually think of when they talk of the genre. The typical stories were those of the fight between ranchers and farmers ; the sheriff's fight against a rich but evil landowner who tries to dominate the town ; the heroic battle of the glorious cavalry against the evil indians ... Some historical events were told again and again, like the lives of Jesse James, Billy the Kid or the Tombstone incident. Great westerns of the times are those of John Ford, Raoul Walsh, Howard Hawks, and many others, too many to mention.
Near the end of the forties, westerns, usually quite stereotypical, became more complex. The Indians were less uniformly evil, violently oppressed by the whiteman, and often justified when they fought back, such as in Delmer Daves' Broken Arrow, John Ford's Cheyenne Autumn or The Searchers, the latter being often seen as the greatest western ever. Some movies would have a less traditional image of the west, such as Nicholas Ray's Johnny Guitar, Samuel Fueller's 40 Horses, or the controversial High Noon by Fred Zinneman, in which Gary Cooper is a sheriff that seeks help against incoming outlaws wanting to gun him down, and can't find any. Just to answer it, Howard Hawks and John Wayne made the classic Rio Bravo, where the sheriff does the right thing and refuses when law-abiding citizens try to help him...
In the sixties the outlaws' violence was shown as what it was, lethal and cruel, and often unjustified, by Sam Peckinpah in The Wild Bunch ; the westerns of the decade were not only the end of the traditional western form, but they also often depicted the end of the frontier era. With the social changes that occured in America in those times, the myth-making of westerns did not connect with the audience anymore. Good and Evil as concepts were also absent of the Spaghetti Westerns, the best of which were Sergio Leone's masterpieces, The Good, The Bad and the Evil and Once Upon A Time In The West. Apart from Clint Eastwood, with his brilliant Unforgiven, western is a forgotten genre nowadays.
Thanks to sid and Starke for input.