You can download OS X 10.7 (Lion) from the App Store by signing in with your Apple ID:
Open the App Store and select Store>Purchases from the menu bar.
You should see an item called 'OS X Lion'. Press the button Download on the right:
Now you have two choices. You can either install Lion on your Mac or create a virtual machine:
Install Lion on your Mac
After download is complete the installer (Applications>Install Mac OS Lion) will start, but unfortunately will immediately abort with this error message:
But you can still install Lion:
- Right-click the installer and select 'Show Package Contents':
The file called 'InstallESD.dmg' is a Lion image in ISO format. Insert a DVD in your optical drive, right click the DMG file and select 'Burn "InstallESD.dmg" to Disc...'. You can also create a bootable flash drive.
Insert the DVD disc and restart your Mac while pressing C. The Mac will start up from the DVD disc and the Lion installation routine will start.
I would recommend that you install Lion on an external harddrive to avoid overwriting your current installation.
Create a virtual machine
If you prefer, you can create a virtual machine in VirtualBox (freeware), VMware Fusion or Parallels and install Lion. According to Apple's licensing policies, you are allowed to virtualize Lion client.
These are the installation instructions for VMware Fusion: http://partnerweb.vmware.com/GOSIG/MacOSX_10_7.html#installation2
Now you can install Xcode 4.2. Download it from the Apple developer site:
Explanation of error
This Version of Mac OS X is not supported on this platform! reason: Mac-6F01561E16C75D06 and workaround.
After following the procedure explained at the beginning of this answer for creating a Lion DVD, the OP mentions in a comment below that this error appears
This Version of Mac OS X is not supported on this platform! reason: Mac-6F01561E16C75D06 when booting from it.
The obscure code
Mac-6F01561E16C75D06 is the Mac model name, synonymous with
MacBookPro9,2 (see this lengthy post), so the error message simply means that the Lion DVD can't be used with the OP's Mac.
But it came with OS X Lion pre-installed, how is this possible?
The reason is that the specific installation of OS X Lion required by the OP's Mac doesn't match the version that can be downloaded from the Mac App Store, as every Mac model comes with a computer-specific build of Mac OS X (see Mike Bombich's answer in this post).
Fortunately, I found a workaround. It worked for me, and I hope it will work for you:
Back up your Mac.
Restart and press ⌘OptionR to force your Mac to enter Internet Recovery mode (this key sequence is mentioned in a cultofmac.com article but surprisingly not in the official Apple documentation).
OS X Internet Recovery needs an Internet connection and lets you start your Mac directly from Apple's servers.
While the Recovery System image is downloaded you'll see:
Wait several minutes until you see the Mac OS X Utilities window:
Select "Reinstall Mac OS X" and press Continue. You can finally install Lion:
As I mentioned earlier: I would recommend that you install Lion on an external harddrive to avoid overwriting your current Mountain Lion installation.
The other possibility is to install a vitual machine (VMware, Parallels or VirtualBox) using the Lion DVD, see above.