Hello dear, If you wanna install GCC 7 & G++7 In Ubuntu you have 2 way to install,
1) you can download & compile GCC source
2) you can install with toolchain
Open your Linux Terminal & enter this commands.
apt-get update && apt-get install -y software-properties-common && add-apt-repository ppa:ubuntu-toolchain-r/test && apt-get update && apt-get install -y gcc-7 g++-7 && update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 60 && update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 60
then you can enter
gcc --version
to see your GCC version.
If you wanna Install GCC & G++ In CentOS 6.9 or etc you can use these commands
yum install centos-release-scl-rh
yum install devtoolset-7
scl enable devtoolset-7 bash
then you can check your GCC version
gcc --version