There were gun salvos, mariachi bands and a red carpet for Cuban President Fidel Castro today when he arrived in Mexico for the first time since he left as guerrilla leader 23 years ago to launch his socialist revolution.

It had to be Latin and emotional as there was even a sense of the return of a prodigal son. Mexican Prsident Jose Lopez Portillo, who received Castro on this wind-blown Mexican island barely 300 miles from Havana, seemed moved. He grabbed Castro with both hands.

"When you left this country," Lopez Portillo told his visitor who wore his perennial military fatigues, "it was for a challenge, an adventure. You return, Mr. President, with certainty, with institution, with the government, and with the dignity won for the people of Cuba. . . . You are one of the personalities of this century."

Castro responded in kind, saying that since he left Mexico on a small yacht with 82 Cuban guerrillas, there have been "immense obstacles, isolation, bloikades. But this great Mexico was the only country in this hemisphere no to break relations with Cuba. As I return, I needn't kiss this soil because I've always carried it in my heart."

Another recent visitor to Mexico, Pope John Paul II, knelt to kiss the ground on arrival.

Although Castro will not be visiting his old haunts in Mexico City and in Tuxpan, the gulf port from which he sailed in 1956, last monthhe finally accepted the latest of numerous invitations from Mexician administrations.

This resort island of 30,000 inhabitants was clearly convenient to both parties. The politically meddle-of-the road Mexican government would regard the likely hero's welcome for Castro in Mexico City as a political headache while the Cubans are known to regard the capital, with its numerous anti-Castro Cuban exiles, as a serious security risk.

Officials on both sides say there is no formal agenda for the two-day meeting but the expected topics include such Thrid World themes as the defense of raw material prices and need for a new international economic order-favorites fof both presidnts.

Castro is expected to invite Lopez Portillo to attend the September summit meetin in Havana of the nonalighed nations. Mexico is not a member of the group.

Mixico would like to see Cuba honor a fishing agreement and keep Cuban shrimp boast out of Mexican waters. Cuba is looking for ways to improve trade with Mexico.

According to the latest available trade figures, in 1977 Cuba imported $34 million worth of Mexican goods,ranging from beans to cotton and steel products. Over the same period Cuba exported only $2.5 million worth of nickle, chrome and small quantities of rum and vegetable oil to Mexico.

On arrival, Castro dismissed the numerous froeign and Mexican press reports that an oil deal between Mexico and Cuba might be signed.

"We are coming to get anything material from Mexico," Castro said. In an apparent reference to President Carter's recent visit here, Castro went on, "We are not coming in search of either Mexican oil or gas, as is very fashionable these days."

Nonetheless, there have been past conversations between Mexico and the Soviet Union-Cuba's current supplier of oil-on a triangular sales agreement to save shipping costs. This could involve the Soviet's sellinng oil to Spain, a client of Mexico, while Mexico would supply the same quantity of oil to nearby Havana.

Jorge Diaz Serrango, the chief of Mexico's state oil monopoly PEMEX, who is participating in the talks, told reporters he had "received no instructions to preapare any oil sales or triangular sales with Cuba." He said Mexico had no oil available to sell until 1981.

At a late luncheon following two hours of talks, Catro said the United States must give Mexicans who go there "just, civilized" treatment because it created the problem.

"Cuba. . .supports the legitimate demand of the Mexicans who emigrate - a fruit of the bitter and inevitable mutilation of the national territory and the underdevelopment imposed by the force, the arrogance and the domination of the United States in the past," Castro said.

Diplomats on both sides have predicted there will be no spectacular outcome from the visit, which is designed rather as an opportunity to discuss such international topics as "the explosive political situation in Central America," as one Mexican official said.

From Lopez Portillo's point of view, the meeting will serve to improve his stance with the left at home - which has criticized his conservative economic policy.

"This visit is part of the traditional Mexican balancing act," said a Mexican Foreign Ministry official. "We've had Carter, the pope, now we have Fidel."

For Castro, the trip to Mexico is his first to the Latin American mainland since 1971, when he visited Chile during the government of his friend Salvador Allende. He also made stopovers at that time in Peru and Ecquador. He also visited Guyana and Trinidad in 1973 and Jamaica in 1977. CAPTION: Picture, Mexican President Lopez Portillo, right, greets Fidel Castro at airport. UPI