Clone magento2 repo on github:

 

 

Set owner:

 

Set files and folders permission:

If you must enter the commands as sudo, use:

 

Run composer:

 

Then install Magento via browser or command line.

 

 

Install Sample Data

this will add the various require to composer.json

 

 

 

Install Sample Data [2nd way]