Any massive body (i.e., a body having mass) like the stars, planets, moons, and any atom in the universe have, what is called, a gravitational potential which results in its gravity. This is described by Newton's Law of Gravity. Why masses cause gravity, we do not know.
So, in short, the earth's mass causes it to have gravity.
Anything that has mass will have gravity ( Exhibit a phenomemon called gravitation) not just black holes.
One way of understanding gravity was put forth by Newton as his law of gravitation. As @christo said, there is no clear knowledge of why it has gravity.
A more generic way to put it would be to say, anything that has mass curves the space around it. The force or gravity you would feel can be considered as the way you are being forced to follow the curved lines instead of your intended path. This is how Einstein's general theory of relativity explains gravitation.
In quantum mechanics, It is speculated that gravity is caused by exchanging particles called gravitons, think of it like the way you would play catch with your friends. Multiple objects having some mass throwing small balls called gravitons at each other. There is no evidence for the existence of gravitons yet, but it explains a lot of things in the quantum realm.
The earth is made from MANY particles, these particles get something called mass, from a thing called the higgs feild, this mass is how much gravity something has, the earth has its mass, and mass warps space time, like when you push your finger on your bed, it creates a curve that goes down, it happens for space, and things get attracted to earth.
The exciting thing is that everything has mass! Even us, but our mass, like some tens of KGs, are too small to create a gravitational pull, to pull other things, even just a centimeter away.