How to Install and Configure the Latest GCC on Ubuntu

Trying to get the latest GCC on Ubuntu can be a bit of a pain, especially with Ubuntu’s default repositories lagging behind. Maybe you just want to compile the newest C++ standards or test some experimental features. Whatever the reason, if you found yourself stuck with an older GCC version, this guide is for you. It walks through the fairly straightforward process of adding a new repository, installing the latest compiler, and making sure your system uses it by default. Fair warning though—sometimes it’s a bit fiddly, and on some setups, things might not go perfectly the first time. Still, with these steps, you should be able to get GCC 14 running, and that’s a big step forward in modern development on Ubuntu.

How to Fix or Upgrade GCC to the Latest Version on Ubuntu

Adding the latest Ubuntu toolchain PPA

This is kind of the secret sauce. Ubuntu’s main repo often delays getting the latest GCC release—like GCC 14. So, adding the Ubuntu Toolchain PPA is usually the way to go. It lets your system pull newer builds directly from the source.

  • Open your terminal (Ctrl + Alt + T), and run:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test

Yup, that’s pretty much it. On some setups, this might throw an error or ask you to confirm with a press of Enter. Sometimes, you’ll need to manually punch in your password.

Note: Always double-check the URL; because of course, Ubuntu has to make it harder than necessary, but this PPA is generally trusted and stable.

Updating your package list

Once the PPA is added, your system doesn’t automatically see the new packages. So… update!

  • Run:

sudo apt update

This command refreshes all repositories and includes the new ones from the PPA. Expect a bit of scrolling, and possibly some warnings about outdated keys, but that’s normal.

After this, your system can see the latest GCC packages available for install.

Installing GCC 14 and G++ 14

Next, tell apt to grab the big guns. You want the latest GCC and G++.

  • Run:

sudo apt install gcc-14 g++-14

This will fetch and install both the C and C++ compilers. It’s kind of nice because now, you can compile in both languages using the newest features — hopefully making your code faster and more modern.

Switching your default compiler to GCC 14

Here’s the tricky part — making sure your system actually uses the new GCC by default instead of the old one. Linux has this cool update-alternatives system that helps manage multiple versions of the same software.

  • Run these commands:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 100
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-14 100

These set the new GCC and G++ as the default. The number 100 is a priority; higher means more favored. Now, if you run gcc --version after this, it should tell you GCC 14 is in place.

Sometimes, on certain setups, you might need to explicitly select the default version via:

sudo update-alternatives --config gcc

This brings up a menu where you can pick the version you want, in case multiple are installed.

Verify everything is working properly

Last step — just do a quick check:

  • Run:

gcc --version

If you see something like gcc (Ubuntu 14.x.x), then you’ve nailed it! Now, your system is ready to compile with the latest features.

Truth be told, on some machines, this sometimes fails the first time, then works after a reboot or a re-login. Maybe it’s some weird path refresh thing, but it’s worth a shot.

Extra Tips & Troubleshooting

If you bump into issues, here are some quick ideas:

  • Make sure your system is fully updated before adding the PPA. Run sudo apt upgrade just to be safe.
  • If you have multiple GCC versions, double-check which your system uses with which gcc.
  • Sometimes, old or conflicting packages cause trouble. Clearing cache with sudo apt autoremove or removing old gcc packages might help.
  • If the new compiler refuses to work, check your PATH environment; /usr/bin should be prioritized, but sometimes custom configs get in the way.

Wrap-up

Installing the latest GCC isn’t always as straightforward as clicking a button, but adding the toolchain PPA and using update-alternatives makes it pretty manageable. If things act up, a reboot or re-configuration usually clears up the confusion. After it’s done, you’ll be able to compile with all the latest standards and features, which is kinda the point, right?

Summary

  • Add the Ubuntu Toolchain PPA
  • Run sudo apt update
  • Install gcc-14 and g++-14
  • Configure default via update-alternatives
  • Verify with gcc --version

Fingers crossed this helps