Water is made of Hydrogen and Oxygen atoms, which are originated from the Sun (the element factory in this solar system). These two elements were present in the material that ended up forming planet Earth more than 4.5 billion years ago. A lot of water molecules ended up at the limit of the Solar System, in the so-called Oort Cloud. It is reasonable to think that the fee water currently present at the surface of planet Earth came part from volcanic gas venting, condensed into water, part from icy comets (originated in the Oort Cloud) that fell on Earth in geologic times (one such impact is interpreted 28 millions years ago, see http://news.nationalgeographic.com/news/2013/10/131011-first-comet-impact-egypt-fragment-science-space/).