Yes, absolutely 🙂 — you can install newer GCC versions on Ubuntu. By default, Ubuntu’s repositories usually lag a bit behind, but you have a few options depending on how bleeding-edge you want to go.
gcc --version
Ubuntu 22.04 ships with GCC 11, and Ubuntu 24.04 with GCC 13. If you need GCC 14 (for -std=c23), you’ll need to add a newer repo or build it.
Ubuntu has an official Toolchain Test Builds PPA maintained by Ubuntu developers.
sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update
sudo apt install gcc-14 g++-14
Now you’ll have gcc-14 and g++-14 alongside your default compiler.
You can check:
gcc-14 --version
If you want gcc to point to the new version:
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 60
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-14 60
Then select the version:
sudo update-alternatives --config gcc