The Fourth of July is famous for other reasons, but today also is the 150th anniversary of the first run of the first street railway on the Pacific Coast - a two-car steam train that ran up San Francisco's Market Street.

The Market Street Railroad, which ran from Third and Market out to Valencia Street and then to 16th Street, was dirty, noisy and ultimately a financial flop, but it was the start of something big.

Rail cars have run on or under Market Street ever since, and the first rail line turned Market Street from an unpaved and undeveloped cow path through towering sand dunes into the city's main stem.

Surveyor Jasper O'Farrell had laid out Market as a grand boulevard in the 1850s, but the infant San Francisco grew up around Portsmouth Square not far from Telegraph Hill. If San Francisco had a main street it was Montgomery, where all the best businesses were located.

Emiliano Echeverria, who has co-written eight books on San Francisco transit, said that in 1860 Market Street had nothing but potential.

It was "off the beaten path," he said. It petered out around Third Street, and west of Third there were only a few houses, and a number of sand hills, some 50 to 60 feet high.

The only public transportation conveyances in the city were horse-drawn omnibuses, which could seat 10 or 12 passengers, jolting along potholed and muddy streets. The omnibuses charged what the traffic would bear - at first the fare was $1 a ride, which was a fortune in those days.

The route of the pioneering Market Street rail line went through "wild country, the middle of nowhere," Echeverria said.

The rail line changed all that. "It set the wheels in motion, if you'll pardon the expression," Echeverria said.

The Market Street train wasn't much - a steam engine that was part locomotive and part passenger car, and a trailer car. If the cars were crowded, passengers could ride on the roof. There was a single track down the middle of Market and up Valencia.

In a couple of years, there were new houses rising on Market Street extending west out to about 12th Street, and the Mission District started to build up. By then, the city had outgrown the two-car steam trains, which were noisy and dirty and took three men to operate.

By 1867, the steam trains were replaced with a new invention: rail cars drawn by horses. Then came a building boom and horse-car lines were built out Valencia, out Hayes, Haight, McAllister and Castro streets. All lines fed into Market.

By 1883, the horse-car lines were converted to cable cars, with a cable slot down the middle. Old-timers used to call everything on the other side of Market Street "South of the Slot."

The cables ran on tight headways; by the turn of the 20th century, a cable car was at the Ferry Building at rush hour every 15 seconds, transit historians say.

The 1906 earthquake and fire finished the Market Street cables, replaced by electric streetcars - on four tracks. The cars made so much noise that "The Roar of the Four" could be heard for miles.

BART built a subway later, and then came the Municipal Railway's Muni Metro system. On a weekday, there are close to 290,000 boardings on the Market Street subway, bus and streetcar systems, the equivalent of the entire population of Buffalo, N.Y.

"Market Street has had rail transit on its surface longer than any other main street in America," says Rick Laubscher, president of the nonprofit Market Street Railway, a partner of the Muni system that operates a streetcar museum at Mission Street and the Embarcadero. It will offer a free exhibit on the old steam railroad starting July 15.