Pope John Paul II appointed 18 new cardinals yesterday, including an 87-year-old Latvian monsignor who became the first cardinal named inside the Soviet Union.

The Polish-born pope also named Warsaw's Archbishop Jozef Glemp and Chicago's Archbishop Joseph Bernardin to the Vatican's Sacred College of Cardinals, raising its membership to 138.

Glemp, who succeeded the late Cardinal Stefan Wyszynski as primate of the Polish church in 1981, has been a cautious supporter of the now outlawed Solidarity union movement.

Bernardin, who succeeded the late Cardinal John Cody as archbishop of Chicago last year, headed the committee of American bishops that drafted the controversial pastoral letter on the immorality of nuclear war. The only American named, he becomes the 10th living American cardinal.

In naming Glemp and Latvian bishop Julijans Vaivods, the pope emphasized his continuing involvement in the religious and political struggles of Eastern Europe.

In naming Bernardin, John Paul underscored his newly intensified interest in arms control, recently evidenced by his strong New Year's Day appeal for cuts in nuclear weapons.

The list of new cardinals announced at the pope's weekly general audience in Vatican City also included the first Jewish convert to be raised to the position, Archbishop of Paris Jean-Marie Lustiger; the Maronite patriarch of Beirut, and two Jesuits, including an 86-year-old French liberal theologian, the Rev. Henri de Lubac, who was elevated directly, without first becoming a monsignor or bishop.

The new cardinals, who will be installed at a special Vatican gathering on Feb. 2, were named from five continents, further diversifying the church's leadership, long dominated by Italians. Only three of the 18 named yesterday are Italians.

Glemp's elevation had long been expected. Poland is one of the world's most Catholic countries and its primate almost automatically becomes a cardinal.

The naming of Vaivods, apostolic administrator of Riga, capital of the Soviet Baltic republic of Latvia, was not seen here as an overt challenge to the Kremlin.

Vatican sources told news services that the Russians had given "tacit agreement" to the move, which was ignored by the Soviet news agency Tass yesterday.

The last cardinal named from the Soviet Union was Jozyf Slipyi, archbishop of Lwow, who was freed from 18 years' imprisonment in 1963 and went into exile in the Vatican, where he still lives. Pope Paul VI named him a cardinal in exile in 1965.

Most of the Soviet Union's 3 million to 4 million Catholics live in the westernmost regions absorbed after World War II, especially the Baltic republic of Lithuania and its smaller neighbor, Latvia.

During the past year, John Paul has made several gestures of concern for Baltic Catholics.

In July he named two apostolic administrators, one of whom had been under a form of house arrest, for two Lithuanian dioceses, and in November he appointed a new auxiliary bishop for Latvia, the first such appointment in 10 years.

While the Soviet Union is officially an atheistic society, the well-organized Lithuanian Catholic community has been able to win a measure of toleration for its faith. Their unauthorized publications have chronicled the attempts of Soviet authorities to harass and suppress the church.

In 1980, a petition signed by 143,869 Lithuanians was presented to Leonid Brezhnev, then president, asking that he order local authorities in Klaipeda to return to Catholics a church, built with donated funds and volunteer labor, that had been confiscated and turned into a concert hall.

Brezhnev ignored the petition, but its filing showed the persistence of Lithuanian Catholics in challenging official actions.

John Paul named two other cardinals from communist countries : Joachim Meisner, archbishop of Berlin, is primate of East Germany's 1.8 million Catholics; Franjo Kuharic, archbishop of Zagreb, leads the church in Croatia, the most Catholic of Yugoslavia's six republics.

The two new French cardinals have unusual backgrounds.

Archbishop Lustiger, the son of Polish Jews, was baptized a Catholic in occupied France in 1940, when he was 14. Three years later, his mother was sent to Auschwitz, the Nazi death camp in Poland, where she died. Father de Lubac, the Jesuittheologian, was often criticized for his writings by Catholic conservatives before the Vatican reforms of the 1960s. He is an expert on the church's relations with atheists.

The other new cardinals are:

*Antoine Pierre Khoraiche, Maronite Christian patriarch of Beirut, who has condemned atrocities by Christian factions in Lebanon.

*Alfonso Lopez Trujillo, archbishop of Medellin, Colombia, chairman of the Latin American Bishops Conference and an outspoken opponent of "liberation theology."

*Michael Kitbunchu, archbishop of Bangkok and Thailand's first cardinal.

*Alexandre do Nascimento, archbishop of Lubango, Angola.

*Bernard Yago, archbishop of Abidjan, Ivory Coast.

*Jose Ali Lebrun Moratinos, archbishop of Caracas, Venezuela.

*Thomas S. Williams, archbishop of Wellington, New Zealand.

*Godfried Danneels, archbishop of Brussels and Malines, Belgium.

*Aurelio Sabattani, secretary of the Vatican supreme court.

*Carlo Maria Martini, Jesuit archbishop of Milan.

*Giuseppe Casoria, head of the Holy Congregation for the Sacraments.

Among those passed over was Archbishop Paul C. Marcinkus, an American who heads the Vatican Bank, implicated in one of Italy's worst banking scandals. Marcinkus acts as the governor of Vatican City, a post that normally carries the rank of cardinal.