Moving to a new Mac?
Learn how to move your files to your new Mac. Do this before you erase the hard drive or follow any other steps.
Create a backup
Be sure you have an up-to-date backup of your important files and data. Learn how to back up your data in OS X.
Sign out of iTunes
Open iTunes. From the menu bar at the top of your computer screen, choose Store > Deauthorize This Computer. When prompted, enter your Apple ID and password. Then click Deauthorize.
Learn more about deauthorizing your computer using iTunes, including how to deauthorize all the computers you've used with your iTunes account.
Sign out of iCloud
If you use Find My Mac or other iCloud features on your Mac, you should first archive or make copies of your iCloud data. After that, choose Apple Menu > System Preferences, click iCloud, and then deselect the Find My Mac checkbox.
Finally, sign out of iCloud. In System Preferences, click iCloud, and then click the Sign Out button.
When you sign out of iCloud, you're asked whether you want to remove iCloud data from your Mac. Your iCloud data will remain on any other devices that are using the same Apple ID.
Sign out of iMessage
If you're using OS X Mountain Lion or later, sign out of iMessage. In the Messages app, choose Preferences > Accounts. Select your iMessage account, then click Sign Out.
Erase and reinstall OS X
To reformat your hard drive and reinstall OS X, follow these instructions. After you reformat your hard drive and reinstall OS X, the computer restarts to a Welcome screen and asks you to choose a country or region. If you want to leave the Mac in an out-of-box state, don't continue with the setup of your system. Instead, press Command-Q to shut down the Mac. When the new owner turns on the Mac, the Setup Assistant will guide them through the setup process.