transfer from iPhone to iTunes Lidbrary

I have to update my iPhone 5 but I have a message saying to transfer purchased items on the iPhone to the iTunes Library before updating.
How do I transfer the apps to the iTunes Library?
Is it done on the iPhone or when the iPone is connected to the computer?
In iTunes, right click on the device, a pop-up should have the toon to transfer purchases... Do that.

Original thread: https://forums.imore.com/threads/transfer-from-iphone-to-itunes-lidbrary.276496/