Militias grabbed power and proliferated quickly as a result of the very weak national army in Libya. Rebuilding a national army and police is the cornerstone of any endeavour to construct a new, functioning state, and maintain security and the rule of law.
The formal Libyan army as it stands today is very weak and marginalised, with most of its estimated 130,000 soldiers and officers sitting idle while drawing their salaries. It has not had new recruits since the revolution, and is now bloated with senior ranking officers, and the lowest rank now a "colonel".
The majority, if not all, of its barracks and equipment have been taken over by the militias.
The root causes of such a weak army in Libya today, can be traced back to decades of systematic neglect by Gaddafi, who ironically used the army to reach power through a military coup in 1969.
However, because other army officers started to emulate Gaddafi, (they began plotting to topple him in many repeated coup attempts), he deliberately neglected and significantly weakened the national conventional army, and replaced it instead with what became very powerful and loyal security brigades.
As one expert on Libya put it: The enfeebled state of the formal army and police was a consequence of Gaddafi marginalising those forces in favour of elite units commanded by his sons, and hence both the army and police had largely evaporated during the revolution that overthrew him.
Once Gaddafi realised, during the revolution of 2011, that his 42-year grip on power was slipping away fast, he deviously released about 26,000 criminal prisoners, almost 200 of whom were facing the death penalty for serious crimes.
He also opened large arms depots for them, in the hope they would use the arms to fight with him against the Libyan revolutionaries.
However, once they possessed large arsenals of weapons, many of these top serious criminals went on to form militias and become part of the militia landscape today, engaging in all types of crime and acting with impunity.
The number of fighters during the revolution was put at around 25,000, yet this number later expanded to over 200,000 due to readily available arms.
A policy was put in place by the first transitional government in post-revolution Libya in 2011, to pay salaries to all those who took part in the uprising and belonged to armed groups which were now rapidly filling the vacuum acting as the new security bodies.
This policy, with the generous salaries it entailed, encouraged unemployed Libyan young men to take up arms and set up their own militias or join existing ones. The policy created a hybrid security system in which very weak "formal" forces of the army and police work alongside very powerful "informal" armed groups that also fell under the legitimacy of the government.
For some, militia life has become a lucrative source of easy money. The rapid growth in numbers and power of armed militias turned out to be one of the biggest problems after the revolution.
They consolidated power through seizing control of strategic state institutions and assets, such as airports, oil facilities, border control, ports and military barracks.
Today, they guard government institutions including ministries, state companies, universities and major state corporations such as telecommunications, sovereign investment funds and banks.
Read more: What does 2018 hold for Libya?
As a result, these institutions are subject to extortion for money and appointments in highly paid jobs. Militias are wielding major power and taking hundreds of thousands in state money, with a complete absence of any form of auditing or accountability.
Both the Libyan political leaders of the National Transitional Council (NTC) - that took over post downfall of Gaddafi - and the international community have made strategic policy mistakes and contributed to creating the militia phenomenon.
It was, in part, the responsibility of the UN to oversee a security sector reform (SSR), and disarmament, demobilisation and reintegration (DDR) policies. The two approaches were not sufficiently recommended to a new and very inexperienced political leadership in Libya, as part of a comprehensive post-conflict reconstruction programme.
Also unhelpfully, other groups in Libya fostered a negative attitude towards the formal Libyan army, which they saw as "Gaddafi's army". This was unfair to the tens of thousands of soldiers and officers belonging to the army who refused to fight against civilians throughout the revolution.
In fact, hundreds of army officers deserted their barracks and joined the revolutionary groups offering them training, vital military expertise and fighting with them against Gaddafi's elite security brigades.
Some groups, mainly Islamists, also proposed the setting up of the Libyan National Guard (LNG) as a parallel military institution that can integrate many militia members temporarily until the formal army has been rebuilt.
However, "secular factions opposed the LNG program, which they saw as a bid by Islamist militias to challenge the regular army". Many feared that once the LNG was established, it would never stand down.
Haftar's model of rebuilding an army named the Libyan National Army (LNA) in the east of Libya, where he imposed total control, has not been supported nationally.
Haftar has been building a combination of official army units with Salafi and civilian/tribal militias; he has also imposed three of his sons and some of his cousins as the main military leaders of his army.
Haftar's LNA is built on loyalty to him, as he uses it as a vehicle for achieving political power. The overwhelming majority of members of the Libyan army in the west and south of Libya do not have allegiance to Haftar, whom they see as a divisive figure hungry for absolute power.
The way Haftar has used his LNA to help him manoeuvre into political power vindicates the fear that a strong national army under the control of a potential dictator could be used to curtail freedoms, suppress political opposition, and be an obstacle to democratic aspirations.
The real challenge facing Libyans today, is how to build a strong, professional national army tasked with maintaining stability, that is governed by the rule of law, and that helps citizens and state to thrive.
Demobilising and integrating hundreds of thousands of militias members into the army should not be the only option, as many of these militias are formed along local, tribal and ideological lines; factors which could impede building a coherent army.
Recruiting them on their individual merits, an ensuring they are strictly disciplined and accountable, is a more feasible option.
Libya needs a highly mechanised and mobile army of about 100,000. This means the old army, where many - including the 75-year-old Haftar - are well passed their retirement age, must be overhauled.
Building a young, strong, national army should become the goal of all political factions, and it should be incorporated into an overall political agreement and national contract.
Such a body could be gradually built up, as the militias are gradually scaled down, to avoid any serious security vacuum that will bring about even more criminality and violence.
The bulk of the young militia members should be enticed away from militia culture through well-constructed capacity building programmes that include training and development, further education and government loans to set up small and medium enterprises (SMEs).
Libya has a very young population. Seventy percent are under the age of 30, and the country also possesses huge natural resource wealth. Once the energy of young Libyans is channelled into acquiring wealth and prosperity through better and safer alternatives than militia life, joining these groups will become far less attractive, causing them to shrivel and wither away from the Libyan scene.
Guma El-Gamaty is a Libyan academic and politician who heads the Taghyeer Party in Libya and a member of the UN-backed Libyan political dialogue process.
Follow him on Twitter: @Guma_el_gamaty
Opinions expressed in this article remain those of the author and do not necessarily represent those of The New Arab