The phrase was originally used by Mao during an emergency meeting of the Chinese Communist Party (CCP) on 7 August 1927, at the beginning of the Chinese Civil War. Mao employed the phrase a second time on 6 November 1938, during his concluding speech at the sixth Plenary Session of the CCP’s sixth Central Committee. The speech was concerned with both the Civil War and the Second Sino-Japanese War, which had commenced the previous year.
The 1938 paragraph containing the phrase is reproduced below; the central phrase (in bold), cited as deriving from the 1938 speech via the Selected Works, is that given in Mao’s Quotations.
Communists do not fight for personal military power, but they must fight for military power for the Party, for military power for the people. As a national war of resistance is going on, we must also fight for military power for the nation. Where there is naivete on the question of military power, nothing whatsoever can be achieved. It is very difficult for the labouring people, who have been deceived and intimidated by the reactionary ruling classes for thousands of years, to awaken to the importance of having guns in their own hands. Now that Japanese imperialist oppression and the nation-wide resistance to it have pushed our labouring people into the arena of war, Communists should prove themselves the most politically conscious leaders in this war. Every Communist must grasp the truth, “Political power grows out of the barrel of a gun.” Our principle is that the Party commands the gun, and the gun must never be allowed to command the Party. Yet, having guns, we can create Party organizations, as witness the powerful Party organizations which the Eighth Route Army has created in northern China. We can also create cadres, create schools, create culture, create mass movements. Everything in Yenan has been created by having guns. All things grow out of the barrel of a gun. According to the Marxist theory of the state, the army is the chief component of state power. Whoever wants to seize and retain state power must have a strong army. Some people ridicule us as advocates of the “omnipotence of war”. Yes, we are advocates of the omnipotence of revolutionary war; that is good, not bad, it is Marxist. The guns of the Russian Communist Party created socialism. We shall create a democratic republic. Experience in the class struggle in the era of imperialism teaches us that it is only by the power of the gun that the working class and the labouring masses can defeat the armed bourgeoisie and landlords; in this sense we may say that only with guns can the whole world be transformed. We are advocates of the abolition of war, we do not want war; but war can only be abolished through war, and in order to get rid of the gun it is necessary to take up the gun.
— Selected Works of Mao Tse-tung, Vol. II, pp. 224-225