Upon being left on Más a Tierra, Alexander Selkirk first built himself a small hut made of sticks, which he covered with the hides of the wild goats he shot using his musket. Their meat would provide him sustenance as well. But after a while his gunpowder ran out, rendering the musket useless. He now had to rely on his wits and physical prowess to capture goats by hand.
From "The Life and adventures of Alexander Selkirk, the real Robinson Crusoe". 1837
For awhile it seems, Selkirk was able to ambush them, but this soon proved too dangerous. On one occasion he slipped down a steep cliff, rolling with his catch in his arms. He was knocked unconscious, and upon waking found the goat dead underneath him; it seems the goat broke his fall and cushioned the impact of landing.
From "The Life and adventures of Alexander Selkirk, the real Robinson Crusoe". 1837
Deciding that it would be much more sensible to try and tame the goats, he built up a stockade around his hut and supplied it with several of the animals, who eventually became somewhat tame and reproduced in their pen. The kids would eventually provide him with companionship as well as food and hides, accompanying the castaway on his walks about the island. Selkirk even made a habit of talking to them regularly, so as to keep up the habit and not forget his language!