g++(-14) and python3.x on Ubuntu

Install g++:

sudo apt install build-essential # install g++ and so on (the g++ here is g++-13)
sudo apt install g++-14 # install g++-14

Set g++ to g++-14 and gcc to gcc-14:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 50 --slave /usr/bin/g++ g++ /usr/bin/g++-13
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 70 --slave /usr/bin/g++ g++ /usr/bin/g++-14

Similarly, to set python to python3.12:

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.12 50
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1

Check all python options:

sudo update-alternatives --config python