1- Get the latest version of iTunes to your computer;

Apple - iTunes - Everything you need to be entertained.

2- Launch iTunes and connect your device to your computer;

3- Select your device in the Source List on the left, under Devices;

4- At this point, iTunes should detect that iOS 4 is available for your “supported” device. If not, hit the “Check for Update” button.

5- iTunes will notify you that a new version of the iPhone operating system is available for download. Accept it by clicking “Download and Install;”

6- Allow iTunes to perform the software update for your device.
IMPORTANT: do not disconnect your device until the update has finished! You will know that the update has been successfully applied when the device reboots and shows the iOS 4 home screen.