First read http://gcc.gnu.org/install/
Make sure you have all Prerequisites installed!
Download all files to ~/opt/downloads
Install all packages to ~/opt/
Download gcc 4.8 from ftp://ftp.gwdg.de/pub/misc/gcc/snapshots/LATEST-4.8/ and unpack it.
wget ftp://ftp.gwdg.de/pub/misc/gcc/snapshots/LATEST-4.8/gcc-4.8-20120930.tar.bz2
tar xjf gcc-4.8-20120930.tar.bz2
cd gcc-4.8-20120930
Download several necessary librarys into the gcc source directory and unpack them.
They will be built together with GCC.
wget ftp://ftp.gmplib.org/pub/gmp-5.0.5/gmp-5.0.5.tar.bz2
tar xjf gmp-5.0.5.tar.bz2
ln -s gmp-5.0.5 gmp
wget http://www.mpfr.org/mpfr-current/mpfr-3.1.1.tar.bz2
tar xjf mpfr-3.1.1.tar.bz2
ln -s mpfr-3.1.1 mpfr
wget http://www.multiprecision.org/mpc/download/mpc-1.0.1.tar.gz
tar xzf mpc-1.0.1.tar.gz
ln -s mpc-1.0.1 mpc
Now configure and build
mkdir $HOME/opt/downloads/gcc-4.8-build
cd $HOME/opt/downloads/gcc-4.8-build
../gcc-4.8-20120930/configure --prefix=$HOME/opt/gcc-4.8 --enable-threads --enable-languages=c,c++,fortran
make
make install
Troubleshooting
/usr/bin/ld: cannot find crt1.o: No such file or directory
/usr/bin/ld: cannot find crti.o: No such file or directory
These files are usually locates in /usr/lib32/ and/or /usr/lib/x86_64-linux-gnu/
Add this to your .bashrc
export LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/:$LIBRARY_PATH