This question already has an answer here:
How can I manually install gcc tarball file in Ubuntu 12.04?
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
You can install packages from source with