During the Great Famine in Ireland (1845-1849), many Irish people were forced to flee their homes due to starvation and lack of resources. They often settled in makeshift communities on the outskirts of cities, building simple shelters from whatever materials they could find. These communities were known as "shanty towns", and the term eventually spread to other parts of the world to describe similar settlements.
While this is one possible origin, the term's exact history is complex and there are other theories as well. However, the association with Irish immigrants and their temporary housing during times of hardship remains a significant part of the term's meaning.