Growing up in the 1950s and 60s, Fidel Castro tended to feature in the most vivid part of the era’s backdrop. He was emblematic of the international rise of communism: he was as vigorous and charismatic as a revolutionary leader should be and seemed intent on creating a new society based on the principle of “from each according to his ability, to each according to his need”. China and the Soviet Union were communist, as was eastern Europe, and the creed was on the march in Asia and Latin America – led by Castro.

I remember, as a schoolboy, listening intently to the radio. Was President Kennedy going to unleash a nuclear war in response to the Soviet Union shipping nuclear warheads to Cuba? Castro had led a revolution and established the Caribbean’s only communist state and now he was colluding with the Russians in creating the capacity in the US’s backyard to attack them with Soviet nuclear missiles, or create a system of better self-defence, depending on which side you were on. We had to be on America’s, but for a day or two we feared a nuclear holocaust unless Khrushchev backed off. I was frightened I would not make it to adulthood.

Not only were these enemy states that could trigger the end of humanity in a nuclear war, China and the Soviet Union were both tyrannous dictatorships that denied fundamental freedoms and human rights. We had to make common cause with the US to deter them militarily and ideologically, and alongside that weed out communist elements in British society, whether turncoat spies or trade unionists. They were deluded quislings bent on undermining Britain from within to create a British communist dictatorship.

But Castro, and perhaps more importantly, his right-hand man, Che Guevara, were ambassadors for what seemed a different kind of communism. They planted doubts in our young minds. While Russian tanks crushed the Hungarians and, later, Dubček’s Prague Spring and Mao’s Red Guards committed countless atrocities, Cuba seemed to represent something different. Maybe communism did not have to collapse into gulags, prison camps, thought control and atrocity after atrocity. Maybe there was a different vision of society than exploitative capitalism or tyrannous communism. Israel’s kibbutzs, representing a new form of communal shared living, and Cuba’s new socialist order might – just might – represent a future in which the idealistic could believe.

Castro speaks to reporters after addressing a National Press Club lunch in Washington DC in 1959, a few months after he seized power. Photograph: Rex/Shutterstock

After all, the Batista regime that Castro and Guevara had challenged and overthrown was corrupt from top to bottom. The oppressed peasantry had given the insurgent revolutionaries safe homes and risked their lives too; the Cuban revolution seemed a genuine revolution from below. Fidel and Che rewarded the Cuban people by breaking up the great estates and handing the land over to those who worked it. They launched a gigantic programme of education to eliminate illiteracy. They made sure no one went hungry. They created the best system of free public health in Latin America.

The deep flaws inherent in being a totalitarian one-party state, with its denial of core freedoms and zero constitutional checks and balances, were yet to show through. Castro’s Cuba seemed self-evidently better than what had preceded it, and much better than the rest of Latin America through which Che had ridden in his famous motorcycle journey, appalled by the poverty he encountered. Yet this was the capitalist system that US defence and foreign policy was bent on supporting, propping up dictators all over Latin America. And to which Fidel had dedicated himself to challenging.

The years 1968 and 1969 seem a long time ago now, but in that joyous expression of youth, counterculture, some of the best rock’n’roll ever played, Woodstock, the student protests in Paris, the rise of feminism, US draft dodgers flooding Europe, Fidel and Che commanded a unique place. It was routine for stalls at the great festivals to sell T-shirts emblazoned with their faces, together with the iconic cap and cigar. They had become an essential ingredient of the counterculture alchemy, the face of revolution, the idea in the back of Mick Jagger and Keith Richards’s minds when they wrote You Can’t Always Get What You Want and Street Fighting Man. How we danced and how most of us got high! We were the insurgents fighting for liberty against social oppression as we wore our hair long, experimented with sex and drugs and lived our lives according to the rules we had made.

Castro’s Cuba began to look forlorn and backward as Latin America addressed its poverty by embracing markets

Yet, as the late and brilliant Sam Beer wrote in Britain Against Itself: The Political Contradictions of Collectivism, paradoxically we were laying the cultural basis of the rise of Thatcherism and Reaganism. When they spoke of the need for more liberty to allow people more bandwidth to live as they chose, it chimed, echoing the great anthems of the 1960s. The backdrop to our lives was changing. Economically, in both Cuba and in Britain, collectivism was running into trouble – the winter of discontent in Britain and economic stagnation in Cuba. News was seeping out about the extent of repression, dysfunction and atrocity in China and the Soviet Union. Books on revolutionary guerrillas and new visions of society gave way to Solzhenitsyn’s account of life in Soviet prison camps – The Gulag Archipelago. Libertarianism was being incubated. China’s miracle growth was not the result of its communism: it was because it was embracing markets and capitalism.

The Soviet Union collapsed; Chinese capitalism, albeit with Leninist overtones, has propelled it to joint world economic leadership. Castro’s Cuba began to look forlorn and backward as Latin America addressed its poverty not by revolution but by embracing markets. Castro, ageing and ill, retained remnants of his charisma over these last few years but his gaunt frame and wide, non-seeing eyes betokened a world that was past.

There was huge relief when Obama dropped the US blockade and restored diplomatic relationships; at last Cuba might start to trade with the world and get rich. When Mick Jagger, an admirer of Mrs Thatcher, and the Stones played in Cuba earlier this year, the irony was complete. The insurgent rock band had long ago transmuted into pro-capitalist entrepreneurs even as they sang about revolution. Now Cuba would tread the same path.

And yet. We did dance for liberty and freedom. But we also danced for a world in which, as Fidel proclaimed, we looked out for each other. Most Cubans want to retain the great egalitarian legacy he has left, even while they try to combine it with a more dynamic economy and genuine political freedoms. The dream remains to combine all three. I dreamed it then. I dream it now.

• Comments will be opened later