There are detailed and easy to follow instructions here
http://support.apple.com/kb/HT4527Which I used when needing to reformat the hard drive of the desktop with our iTunes music. Most of our music comes from historical CDs, not the iTunes store.
Years & years ago it wasn't so easy to transfer music to a new computer or hard drive. Now it is very simple. I used an external hard drive to copy the files over to, reformatted the drive, then decided to load the tunes to another desktop instead. It was seamless; just needed to link the program to the location where I copied the library. The instructions explain it step by step.