Skip to content

Install several GCC versions on Ubuntu

Launch the following script to have several versions of GCC on Ubuntu alongside the default one, manage the different GCC versions using update-alternatives. This works also for Windows Subsystem for Linux.

Click to view
bash
#!/bin/bash
# add gcc 13 and gcc 14 to Ubuntu 24.04
# launch this script using "sudo"
# check for non official gcc versions on:
# https://launchpad.net/~ubuntu-toolchain-r/+archive/ubuntu/test?field.series_filter=

# install the default building tools
apt update
apt install -y build-essential software-properties-common

# install other GCC versions
apt install -y gcc-14 g++-14

# configure the alternatives for gcc and g++, setting a higher priority to a newer version (ymmv)
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 50 --slave /usr/bin/g++ g++ /usr/bin/g++-13
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 60 --slave /usr/bin/g++ g++ /usr/bin/g++-14

# check or change the alternatives configuration
update-alternatives --config gcc

Install several Clang versions on Ubuntu

Launch the following script to have several versions of Clang on Ubuntu alongside the default one: install some Clang versions using the LLVM Ubuntu/Debian packages and manage the different Clang versions using update-alternatives. This works also for Windows Subsystem for Linux.

Click to view
bash
#!/bin/bash
# add Clang 18 and Clang 19 to a clean Ubuntu
wget https://apt.llvm.org/llvm.sh
sudo apt update
sudo bash llvm.sh 18
sudo bash llvm.sh 19

# configure the alternatives for clang and llvm-profdata, setting a higher priority to a newer version (ymmv)
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-19 60 --slave /usr/bin/clang++ clang++ /usr/bin/clang++-19 --slave /usr/bin/llvm-profdata llvm-profdata /usr/bin/llvm-profdata-19
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-18 40 --slave /usr/bin/clang++ clang++ /usr/bin/clang++-18 --slave /usr/bin/llvm-profdata llvm-profdata /usr/bin/llvm-profdata-18

# check or change the alternatives configuration
sudo update-alternatives --config clang

# to uninstall a Clang version
# LLVM_VERSION=18
# sudo apt purge -y clang-$LLVM_VERSION lldb-$LLVM_VERSION lld-$LLVM_VERSION clangd-$LLVM_VERSION && sudo apt autoremove -y

Install a pull request

The script below fetches and checks out a pull request. Assuming the script is named pull.sh and is in the current directory, it is used as

sh
./pull.sh PULL_ID
Click to view
sh
#!/bin/sh
BRANCH_NAME=PR$1
git checkout master
git branch $BRANCH_NAME -D
git fetch origin pull/$1/head:$BRANCH_NAME
git checkout $BRANCH_NAME