Skip to content

Instantly share code, notes, and snippets.

@jlblancoc
Last active March 29, 2025 09:19
Show Gist options
  • Save jlblancoc/99521194aba975286c80f93e47966dc5 to your computer and use it in GitHub Desktop.
Save jlblancoc/99521194aba975286c80f93e47966dc5 to your computer and use it in GitHub Desktop.
Installing gcc-7 & g++-7 in Ubuntu 16.04LTS Xenial

Run the following in the terminal:

Install the gcc-7 packages:

sudo apt-get install -y software-properties-common
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update
sudo apt install g++-7 -y

Set it up so the symbolic links gcc, g++ point to the newer version:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 60 \
                         --slave /usr/bin/g++ g++ /usr/bin/g++-7 
sudo update-alternatives --config gcc
gcc --version
g++ --version

# This one if you want the **all** toolchain programs (with the triplet names) to also point to gcc-7. 
# For example, this is needed if building Debian packages.
# If you are already are root (e.g. inside a docker image), remove the "sudo" below.
ls -la /usr/bin/ | grep -oP "[\S]*(gcc|g\+\+)(-[a-z]+)*[\s]" | xargs sudo bash -c 'for link in ${@:1}; do ln -s -f "/usr/bin/${link}-${0}" "/usr/bin/${link}"; done' 7
@rancheng
Copy link

rancheng commented Nov 1, 2020

don't forget to update this executable:

update-alternatives --install /usr/bin/x86_64-linux-gnu-gcc x86_64-linux-gnu-gcc /usr/bin/x86_64-linux-gnu-gcc-7

@justin4ai
Copy link

Hello, is there any way to do this without sudo privilege?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment