This is a hotly debated topic, and even has its own name: abiogenesis. One widespread thought is that RNA, not DNA, was the first building block of life. The replication of this RNA-based life required multiple resources which resulted in competition and natural selection among lifeforms. Then DNA arose and formed proto-cells. How exactly life arose in the first place is still at least partially uncertain.