I am from Libya. Because of war all the embassies have closed in my country. Would it be possible for me to apply for a visa in a different country?
Independent of the reason, it is quite common that not all countries are represented everywhere with a diplomatic mission. In these cases, consular services are often offered by offices in a neighbouring country or by a third country.
Depending on which country you want to visit, you have to check yourself where to apply for a visa. It is hard to give general advice and a far too broad topic for one question to give you advice an all the roughly 200 countries you may want to visit.
But let's take Norway as an example, since they don't have a regular diplomatic mission in Libya and it was easy to find online information. Libyan citizens intending to visit Norway must apply for short-term visas at the German embassy in Tripoli and for long-term visas at the Norwegian embassy in Algiers. If the German embassy in Tripoli should close (it seems to be open at the moment), I would suppose that the Norwegian embassy in Algiers would be able to help with short-term visas as well.