Cyberithub

How to Update or Upgrade GCC to Latest Version on Ubuntu/Debian

Advertisements

In this article, we will see how to update or upgrade gcc compiler to the latest version. Many times you might have observed that when you are compiling source code of any of the packages to install then due to older version of gcc, compilation gets failed and it asks you to install the latest gcc version to proceed with the compilation. This becomes even more worse when you try to update or upgrade gcc from default Ubuntu repo but all you got on the output is that latest version already installed. If you are also facing this problem then don't worry, just follow the steps explained in below section to get the latest version of gcc installed in your system.

 

How to Update or Upgrade GCC to Latest Version on Ubuntu/Debian

How to Update or Upgrade GCC to Latest Version on Ubuntu/Debian

Also Read: How to Install Amazon Workspaces Client on Ubuntu 20.04 LTS

Step 1: Prerequisites

a) You should have a running Ubuntu/Debian System.

b) You should have sudo or root access to run privileged commands.

c) You should have apt or apt-get and add-apt-repository utilities available in your System.

 

Step 2: Update Your System

Before upgrading gcc to latest version, make sure you have all the latest available updates installed in your system by using sudo apt update && sudo apt upgrade command as shown below.

cyberithub@ubuntu:~$ sudo apt update && sudo apt upgrade
Hit:1 https://d3nt0h4h6pmmc4.cloudfront.net/ubuntu focal InRelease
Hit:2 https://dl.winehq.org/wine-builds/ubuntu focal InRelease
Hit:3 https://dl.google.com/linux/chrome/deb stable InRelease
Hit:4 http://ppa.launchpad.net/flatpak/stable/ubuntu focal InRelease
Hit:5 http://in.archive.ubuntu.com/ubuntu focal InRelease
Hit:6 http://security.ubuntu.com/ubuntu focal-security InRelease
Hit:7 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:8 http://ppa.launchpad.net/gencfsm/ppa/ubuntu focal InRelease
Hit:9 https://download.sublimetext.com apt/stable/ InRelease
Hit:10 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease
Hit:11 http://ppa.launchpad.net/juju/stable/ubuntu focal InRelease
Hit:12 http://ppa.launchpad.net/libreoffice/ppa/ubuntu focal InRelease
Hit:13 http://ppa.launchpad.net/mojo-maintainers/ppa/ubuntu focal InRelease
Reading package lists... Done
Building dependency tree
Reading state information... Done
2 packages can be upgraded. Run 'apt list --upgradable' to see them.
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
Get more security updates through Ubuntu Pro with 'esm-apps' enabled:
node-hosted-git-info python2.7-minimal python2.7 node-tar libgsasl7
libopusfile0 libjs-jquery-ui libsdl2-2.0-0 libsdl2-2.0-0
libpython2.7-minimal libpython2.7-stdlib
Learn more about Ubuntu Pro at https://ubuntu.com/pro
#
# You can verify the status of security fixes using the `pro fix` command.
# E.g., a recent Ruby vulnerability can be checked with: `pro fix USN-6219-1`
# For more detail see: https://ubuntu.com/security/notices/USN-6219-1
#
The following packages have been kept back:
xdg-desktop-portal xdg-desktop-portal-gtk
0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.

 

Step 3: Add Repo

You need to add a PPA repo to get the latest version of gcc compiler. This can be done by running sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test command as shown below.

cyberithub@ubuntu:~$ sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
Hit:1 https://d3nt0h4h6pmmc4.cloudfront.net/ubuntu focal InRelease
Hit:2 https://dl.winehq.org/wine-builds/ubuntu focal InRelease
Hit:3 https://dl.google.com/linux/chrome/deb stable InRelease
Hit:4 http://ppa.launchpad.net/flatpak/stable/ubuntu focal InRelease
Hit:5 http://in.archive.ubuntu.com/ubuntu focal InRelease
Hit:6 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:7 http://security.ubuntu.com/ubuntu focal-security InRelease
Hit:8 http://ppa.launchpad.net/gencfsm/ppa/ubuntu focal InRelease
Hit:9 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease
Hit:10 http://ppa.launchpad.net/juju/stable/ubuntu focal InRelease
Hit:11 https://download.sublimetext.com apt/stable/ InRelease
Hit:12 http://ppa.launchpad.net/libreoffice/ppa/ubuntu focal InRelease
Hit:13 http://ppa.launchpad.net/mojo-maintainers/ppa/ubuntu focal InRelease
Get:14 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal InRelease [23.8 kB]
Get:15 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal/main amd64 Packages [24.9 kB]
Get:16 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal/main i386 Packages [22.5 kB]
Get:17 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal/main Translation-en [10.2 kB]
Fetched 81.4 kB in 5s (16.9 kB/s)
Reading package lists... Done

 

Step 4: Update System Cache

After adding the repo, you need to update the system cache using sudo apt update command as shown below. This will update system about the newly added repo along with all the packages available.

cyberithub@ubuntu:~$ sudo apt update
Hit:1 https://dl.winehq.org/wine-builds/ubuntu focal InRelease
Hit:2 https://d3nt0h4h6pmmc4.cloudfront.net/ubuntu focal InRelease
Hit:3 https://dl.google.com/linux/chrome/deb stable InRelease
Hit:4 http://in.archive.ubuntu.com/ubuntu focal InRelease
Hit:5 http://security.ubuntu.com/ubuntu focal-security InRelease
Hit:6 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:7 http://ppa.launchpad.net/flatpak/stable/ubuntu focal InRelease
Hit:8 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease
Hit:9 http://ppa.launchpad.net/gencfsm/ppa/ubuntu focal InRelease
Hit:10 https://download.sublimetext.com apt/stable/ InRelease
Hit:11 http://ppa.launchpad.net/juju/stable/ubuntu focal InRelease
Hit:12 http://ppa.launchpad.net/libreoffice/ppa/ubuntu focal InRelease
Hit:13 http://ppa.launchpad.net/mojo-maintainers/ppa/ubuntu focal InRelease
Hit:14 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal InRelease
Reading package lists... Done
Building dependency tree
Reading state information... Done
17 packages can be upgraded. Run 'apt list --upgradable' to see them.

 

Step 5: Install Latest Version of GCC

Now you can install the latest version of gcc, that is gcc-11(this is the latest version available at the time of writing this article) using sudo apt install gcc-11 command as shown below. This will download and install the package along with all its dependencies. If you are looking for any other version then all you need to do is to replace 11 with that version. In that case you need to run sudo apt install gcc-xx command where xx is the required version.

cyberithub@ubuntu:~$ sudo apt install gcc-11
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
cpp-11 gcc-11-base gcc-13-base gcc-13-base:i386 libasan6 libatomic1 libatomic1:i386 libcc1-0 libgcc-11-dev libgcc-s1 libgcc-s1:i386 libgomp1 libitm1
liblsan0 libquadmath0 libtsan0 libubsan1
Suggested packages:
gcc-11-locales gcc-11-multilib gcc-11-doc
The following NEW packages will be installed:
cpp-11 gcc-11 gcc-11-base gcc-13-base gcc-13-base:i386 libasan6 libgcc-11-dev
The following packages will be upgraded:
libatomic1 libatomic1:i386 libcc1-0 libgcc-s1 libgcc-s1:i386 libgomp1 libitm1 liblsan0 libquadmath0 libtsan0 libubsan1
11 upgraded, 7 newly installed, 0 to remove and 6 not upgraded.
Need to get 37.2 MB of archives.
After this operation, 109 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal/main amd64 gcc-13-base amd64 13.1.0-8ubuntu1~20.04.2 [19.1 kB]
Get:2 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal/main i386 gcc-13-base i386 13.1.0-8ubuntu1~20.04.2 [19.1 kB]
Get:3 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal/main i386 libgcc-s1 i386 13.1.0-8ubuntu1~20.04.2 [66.9 kB]
Get:4 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal/main amd64 libgcc-s1 amd64 13.1.0-8ubuntu1~20.04.2 [58.3 kB]
Get:5 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal/main amd64 gcc-11-base amd64 11.4.0-2ubuntu1~20.04 [19.3 kB]
Get:6 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal/main amd64 cpp-11 amd64 11.4.0-2ubuntu1~20.04 [9,225 kB]
Get:7 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal/main amd64 libcc1-0 amd64 13.1.0-8ubuntu1~20.04.2 [44.0 kB]
Get:8 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal/main amd64 libtsan0 amd64 11.4.0-2ubuntu1~20.04 [2,100 kB]
Get:9 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal/main amd64 libgomp1 amd64 13.1.0-8ubuntu1~20.04.2 [127 kB]
Get:10 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal/main amd64 libitm1 amd64 13.1.0-8ubuntu1~20.04.2 [26.5 kB]
Get:11 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal/main i386 libatomic1 i386 13.1.0-8ubuntu1~20.04.2 [7,976 B]
Get:12 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal/main amd64 libatomic1 amd64 13.1.0-8ubuntu1~20.04.2 [9,596 B]
Get:13 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal/main amd64 libasan6 amd64 11.4.0-2ubuntu1~20.04 [2,145 kB]
Get:14 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal/main amd64 liblsan0 amd64 13.1.0-8ubuntu1~20.04.2 [1,112 kB]
Get:15 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal/main amd64 libubsan1 amd64 13.1.0-8ubuntu1~20.04.2 [1,021 kB]
Get:16 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal/main amd64 libquadmath0 amd64 13.1.0-8ubuntu1~20.04.2 [146 kB]
Get:17 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal/main amd64 libgcc-11-dev amd64 11.4.0-2ubuntu1~20.04 [2,374 kB]
Get:18 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal/main amd64 gcc-11 amd64 11.4.0-2ubuntu1~20.04 [18.7 MB]
Fetched 37.2 MB in 30s (1,228 kB/s)
Selecting previously unselected package gcc-13-base:amd64.
(Reading database ... 253499 files and directories currently installed.)
Preparing to unpack .../gcc-13-base_13.1.0-8ubuntu1~20.04.2_amd64.deb ...
Unpacking gcc-13-base:amd64 (13.1.0-8ubuntu1~20.04.2) ...
Selecting previously unselected package gcc-13-base:i386.
Preparing to unpack .../gcc-13-base_13.1.0-8ubuntu1~20.04.2_i386.deb ...
Unpacking gcc-13-base:i386 (13.1.0-8ubuntu1~20.04.2) ...
............................................................

 

Step 6: Link to the latest version

After successfully installing the package, you need to link the compiler to detect this latest version by using sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 20 command. If you see output like below then it confirms that linking went successful.

cyberithub@ubuntu:~$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 20
update-alternatives: using /usr/bin/gcc-11 to provide /usr/bin/gcc (gcc) in auto mode

 

Step 7: Check Version

If you now check the gcc version using gcc --version command then you will see it will show as version 11.4.0. This confirms that gcc is successfully upgraded to latest version.

cyberithub@ubuntu:~$ gcc --version
gcc (Ubuntu 11.4.0-2ubuntu1~20.04) 11.4.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

2 thoughts on “How to Update or Upgrade GCC to Latest Version on Ubuntu/Debian”

  1. I used the same instruction for upgrading GCC from version 11 to 13. Just replaced gcc-11 with gcc-13 wherever required. The process worked smoothly.

    Reply

Leave a Comment