CAIRO, Egypt (AP) _ Despite his reputation as an erratic leader, Moammar Khadafy has consistently steered his nation of some 3 million people according to a philosphy of Arab unity marked by hostility to Israel and to ''imperialism. ''

Khadafy, Libya's leader for nearly 17 years, sees himself as the guardian of the pan-Arab, socialist ideals of the late Egyptian President Gamal Abdel- Nasser.

Libya celebrates each year the anniversary of the July 26, 1952 Nasserite coup in Egypt, even though it's hostile toward the Cairo government.

Western and Arab diplomats believe it is Khadafy's messianic view of Libya's role in the world that has often put the mercurial colonel in conflict not only with the United States but with other Arab leaders who do not share his views.

As an opponent of what he considers imperialism, Khadafy has championed causes of such diverse groups as Indians in the United States, Moslem rebels in the Philippines and the Irish Republican Army.

He has backed radical factions of the Palestine Liberation Organization opposed to a peaceful settlement with Israel, financed opponents of deposed President Gaafar Nimeiri in Sudan and is believed to have supported a bumbling coup attempt against the late President Anwar Sadat in Egypt in April 1974.

As a champion of pan-Arabism, Khadafy has unsuccessfully sought political unity at various times with Egypt, Sudan, Tunisia, Algeria and Morocco, only to be rebuffed each time.

Nevertheless, Khadafy is one of the few Arab leaders who openly supports Iran in its war with Iraq, whose government he condemns as fascist.

Although he is clearly Libya's strongman, Khadafy shuns formal titles and holds no office beyond ''guide of the revolution.'' He calls his country ''the Socialist Peoples' Libyan Arab Jamahiriya,'' roughly translated from Arabic as ''state of the masses.''

Khadafy's political and social philosophy centers around the belief that Arab countries must purge themselves of Western and Marxist cultural influences and build a popular society based on principles of the Moslem holy book Koran.

Khadafy launched his cultural revolution in April 1973, nearly four years after deposing King Idris and closing U.S. and British bases in the North African country. Khadafy vowed ''to destroy imported ideologies, whether Eastern or Western.''

The following month, he announced his ''third international theory'' - a merger of Islamic fundamentalism and socialist principles with respect for privatproperty.

The bible of Khadafy's philosophy is his ''Green Book,'' a collection of his political ideas. The book is required reading in Libyan schools, and newscasts on Libyan Radio begin with recitations of passages, read in sonorous tones reminiscent of Koranic recitations.

Khadafy calls his theory ''an alternative to capitalist materialism and communist atheism,'' and with the Green Book as his guide, he set about to reorganize Libyan politics along lines unique in the Arab world.

Under Khadafy's leadership, the country's national assembly, or the General Peoples' Congress, in 1977 abolished most state institutions and changed the official name of the country to conform to Khadafy doctrine.

The cabinet was replaced by a General Peoples' Committee, with members designated as secretaries in charge of what had been ministries. Peoples' committees were established throughout the country, supposedly to enable the public to take a greater role in the running of the country.

Establishment of he committees also allowed Khadafy to dismiss local officials opposed to his ideas. In line with the doctrine of ''popular control,'' Khadafy urged Libyans outside the country to take over the country's embassies and replace them with ''peoples' bureaus.'' That is the term by which Libyan embassies are known today.

Khadafy's efforts to export his ideas throughout the Arab world have been less successful. His call for 40,000 Libyans to march into Egypt to demand union in 1973 ended with Egyptian troops turning back the marchers 200 miles west of Cairo.

The two neighboring countries fought a brief border war in 1977 which ended after Egyptian troops overran an oasis a few miles inside Libya.

Libyan-backed factions in Lebanon and the PLO have failed to win broad support. The Sudanese military government which overthrew Nimeiri last April has made overtures to Libya, but pro-Libyan political groups within the country are believed to have little popular following and have split over internal disputes.