Virginia's two candidates for governor drew sharp and often caustic portraits of each other in their first television debate last night as they differed over how they would govern the state.

Democrat Gerald L. Baliles and Republican Wyatt B. Durrette both stayed on the attack for most of their 60-minute debate on public television, as each hit at what he charged were his opponent's weaknesses and evasiveness.

Baliles, who was elected state attorney general in the Democratic Party's 1981 sweep, sought to cast himself as the more compassionate candidate who would place a high priority on the needs of minorities and build on the program of Democratic Gov. Charles S. Robb.

He said his administration would spend more money on public education and work to improve the state's frequently criticized voter registration system. He stressed his experience in state government and charged that Durrette had not been elected to office in 10 years and has merely been "standing on political sidelines and criticizing."

Durrette, who lost the attorney general's race to Baliles four years ago, portrayed himself as more conservative and, at the same time, more aggressive, saying he would attack problems the Democrats have failed to resolve.

The 47-year-old former Fairfax County legislator said he would "make our prisons secure again" and charged that Baliles would be interested in expanding government and "spending money the way we've always spent it."

Combativeness was evident throughout the debate. At one point, after Durette answered a question on law enforcement issues, Baliles snapped: "Ol' Wyatt just walked away from that question.

Durrette, recalling a year of crises in the state's corrections system and overcrowded local jails, ridiculed Baliles' record as attorney general, charging that "when we needed leadership . . . he was silent."

Baliles, invoking Robb's name four times, said:

"I will continue to build on the programs of Gov. Robb. My opponent has attacked those programs," Baliles said in his opening remarks.

Durrette said Baliles is a Democrat interested in expanding government and "spending money the way we've always spent it . . . . That's not good enough."

Neither candidate appeared to make any major mistakes as they sparred over education, transportation and voter registration, and each said later he had outperformed the other.

"I'm comfortable with my performance," Baliles said as he stepped off the studio stage at WNVC-TV in Fairfax County. "I thought he was the one attacking."

Durrette said he believed he did "very well . . . . I think he's the Jerry I've seen a lot of times before. He tends to be critical, trying to be cute; if any one evaded, he did."

Both appeared stiff in the early minutes but warmed to the camera as they also discussed such diverse issues as the state's role in combating acquired immune difficiency syndrome (AIDS) and whether the state should support sanctions against South Africa.

Both candidates said decisions to allow AIDS victims to attend public schools should be made by local school boards with guidance from the state.

On South Africa, Baliles denounced its racial segregation and apartheid policies and said he would consider state action to limit investment there. "They erected a system that is unbelievable for the Western World," he said.

Durrette said he was reluctant to do anything that would make life worse for blacks in South Africa and said the state should await action by President Reagan and the Congress. Baliles pointedly reminded him that Reagan already has imposed some limited sanctions.

On voter registration issues in the state, Durrette said Virginia "is doing a good job" and said he would not support any "wholesale changes." Baliles said he favored "making registration a little bit easier." He said the state still has too many barriers to registration for the handicapped and haphazard policies by registrars that discourage some voters.

The two candidates kept up their running debate over elementary and high school education, which has emerged as a key difference between the two.

Durrette repeated that he wants to spend more money for education, but only if it is coupled with reforms, such as a merit pay plan for teachers and other initiatives.

Baliles said the state has imposed numerous reforms on local governments but failed to give them money to implement them. "If we want a good education system, we have to pay for it," Baliles said. "That's a reform of the highest order."

Asked if race or gender should be an issue in the Nov. 5 elections, Baliles launched a strong defense of his running mates, the first black and the first woman nominated by a major party for statewide office.

"Ours is a ticket of diversity; theirs is one of blandness," Baliles said, referring to state Sen. L. Douglas Wilder of Richmond, his party's nominee for lieutenant governor, and state Del. Mary Sue Terry of Patrick County, the nominee for attorney general.

Durrette responded that he did not believe that "race or gender should play a part in this campaign."

Durrette also plugged his ticket mates, saying he is pleased with state Sen. John H. Chichester of Stafford County, the GOP nominee for lieutenant governor, and Del. W.R. (Buster) O'Brien of Virginia Beach, running for attorney general.

On transportation, Baliles said he would establish a critical needs commission to study highway issues for the 21st century, which he noted was only 15 years away.

Durrette quickly replied that there are "some problems you can study for eternity," and said the commission would be irrelevant if the state doesn't solve its current problems.