There are four different explanations for how the gang acquired Scooby:
Scooby Goes Hollywood - The gang picked Scooby up at a pet store.
Happy Birthday Scooby-Doo & A Pup Named Scooby-Doo - the gang has had Scooby since they were children.
Scooby-Doo! The Mystery Begins - Scooby jumped in Shaggy's window after he saw ghosts.
Scooby Apocalypse (comics) - Shaggy befriends Scooby in a warehouse (The Complex)