Firstly, input
sudo apt-get update
in the terminal to update the system software.
Then,input
sudo apt-get install build-essential
to install some essential tools include g++,etc.
You can input g++ --version to show g++ updated version