Islam was from the beginning since Adam was created. The minds were ready to understand the unity and power of God when Muhammad started explaining what Islam is, submission to God, the one and only.
Getting back to you question, Ibrahim was a prophet of God, he worshipped God, the one and only most powerful, he built the Ka'ba on God's command. Although there were kings who tried to destroy it, it was only damaged but then rebuilt again.
After that, the idol worshippers started storing their idols in the Ka'ba, and worshipped the idols, however, when the time came, Muhammad (prophet) went and removed all the idols and made the Ka'ba pure, like when it was built by Ibrahim and his son (Ishmael).