1. sudo apt-get install software-properties-common
2. sudo add-apt-repository ppa:ubuntu-toolchain-r/test
3. sudo apt-get update
4. sudo apt-get install gcc-6 g++-6
5. sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 30 --slave /usr/bin/g++ g++ /usr/bin/g++-6
6. sudo update-alternatives --config gcc
7. g++ --version