On June 30, 1961, the departure of Boston’s first Hyannis-bound train in years was met with glee by the 176 passengers on its maiden voyage, with one train operator declaring, “It’s good to be back on this run.”

On the last Friday of June 1984, Governor Michael S. Dukakis smashed a bottle of champagne on another train, the first to depart Boston bound for Cape Cod in nearly two decades, and declared it “the Spirit of Massachusetts.”

And on Friday afternoon, Cape Cod rail service will make a comeback once again, with passengers set to climb aboard the 5:12 p.m. CapeFlyer at South Station as it departs for Hyannis, the latest iteration in an on-again-off-again history of Boston-Cape train service that has spanned more than a century.

The train is scheduled to run Fridays, Saturdays, and Sundays from Memorial Day through Labor Day. A trip from ­Boston to Hyannis runs two hours and 40 minutes.

Transportation officials hope that the service, run by the Massachusetts Bay Transportation Authority and the Cape Cod Regional Transit ­Authority, using a double-decker commuter rail train, will be popular enough to pay for ­itself through fares and on-train advertising.

“The problem has always been on these services that they never made enough money to cover the operating costs,” said Bradley H. Clarke, a transit historian. “It has always suffered from a financial strain that brought service to a swift close.”

It is a fate T officials are hoping to avoid this time around.

The first train reached Hyannis in 1854. Rail service was extended farther along the Cape in ensuing decades; in 1869, when a train first arrived in Wellfleet, it was met with cheering crowds and a song written by a local minister: “The great Atlantic railroad for old Cape Cod; all hail! Bring on the locomotive, lay down the iron rail.”

The ride down to the Cape, on trains named Comet and ­Pilgrim and Highland Light, became synonymous with the smell of salt marshes filling swanky dining cars as they rolled past cranberry bogs, lush farmland, and the backyards of quaint Cape cottages.

On Friday nights the train was filled with fathers in suits, headed south to spend the weekend with wives and children headquartered on the Cape for the summer.

But the rise of the automobile led to a fall in popularity. Beginning in the 1930s, service was withdrawn from parts of the Cape, with all service ending in 1958.

It was resumed in 1961 and ran until the New Haven Railroad, which provided the service, went bankrupt. In 1984, it reemerged, as part of the privately owned Cape Cod and Hyannis Railroad.

Again and again, ridership flagged. State legislators squabbled over whether to provide subsidies, then eliminated all aid to the rail line. Train service sputtered to a halt.

“You could sit there and have a pretty good meal all the way down to the Cape, and of course they served drinks and it was a very agreeable way to go,” Clarke said. “But the service didn’t really pay for itself.”

George Rizer/Globe File/1984

Trains have run between Boston and Cape Cod on and off since 1854. The last iteration was launched in 1984.

Beverly A. Scott, general manager of the MBTA, was ­insistent last week that this ­iteration of the Cape service will be popular enough to put it into the black.

Adding the service did not require a significant investment in infrastructure, she said: The tracks already exist, and the T needed only to slap a new decal on the outside of the commuter rail train that will be used. Besides, she said, vehicle traffic to the Cape is worse than ever. On the CapeFlyer, getting there is part of the fun.

“I think this one’s going to be a no-brainer,” Scott said.

Transportation officials are banking on the train’s nostalgic appeal to New Englanders and tourists foggy-eyed for the glamorous train travel days of yore.

During the 1961 debut, trainman Joseph Valelly told the Globe that he had missed the familiarities of the Cape Cod route. “I could count on losing five pounds between Boston and Wareham,” Valelly said, “because the trains were so crowded.”

Another passenger, asked what he thought about the service, waved away the reporter.

“Holy cow,” the man said. “Don’t put my name in the ­paper. If my boss finds out I made the 4:50 train, I’ll get fired!”

When the train service was reintroduced in 1984, the maiden voyage departed an hour late, but few passengers were concerned.

Debee Tlumacki for the Boston Globe

Stephen Bilski, 11, of Yarmouth waved at the CapeFlyer as it made a trial run from Boston to Hyannis Thursday.

“There was no air conditioning,” the Globe reported, “but most of the windows opened, and the breeze was pleasant.”

In that iteration, train cars from the early 1900’s had been reclaimed and refurbished, their exteriors painted hunter green, leaving the passenger service with a decidedly retro — and hodgepodge — feel.

Some cars featured upholstered benches, while others had wooden seats. One, the ­Nobska dining car, was built in 1912, refurbished for the 1980 Winter Olympics at Lake ­Placid, then purchased at an auction to join the Cape Cod and Hyannis Railroad fleet. That car was a favorite among passengers, complete with ruby-­colored velvet chairs, ­mahogany dining tables, stained glass partitions, and Victorian chandeliers.

Frances Turner, traveling with her daughter on the train’s first trip to the Cape marveled from the seat of the elegant parlor car. “It’s so exciting,” she declared. “It’s just like an Agatha Christie novel.”