Installing Updated GCC and GDB on Ubuntu Systems
To obtain recent releases of the GNU Compiler Collection (GCC) and GNU Debugger (GDB) on Ubuntu, alternative approaches beyond the default package repositories are required. The following methods enable installation of updated toolchain components.
PPA Installation Method
The Ubuntu Toolhcain PPA provides updated compiler and debugger packages. Execute these terminal commands:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update
sudo apt install gcc-14 g++-14
sudo apt install gdb
To configure the new compiler as default:
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 70
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-14 70
Verify installations with:
gcc --version
gdb --version
Source Compilation Approach
To direct installation from source code:
- Install prerequisites: ```
sudo apt install build-essential libgmp-dev libmpfr-dev libmpc-dev flex bison
- Download and extract source: ```
wget https://ftp.gnu.org/gnu/gcc/gcc-14.1.0/gcc-14.1.0.tar.gz
tar -xzf gcc-14.1.0.tar.gz
cd gcc-14.1.0
- Configrue build environment: ```
mkdir build-dir
cd build-dir
../configure --prefix=/usr/local/gcc-14.1 --enable-languages=c,c++ --disable-multilib
- Compile and install: ```
make -j$(nproc)
sudo make install
- Update system paths: ```
echo 'export PATH=/usr/local/gcc-14.1/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
Snap Package Installation
For GDB installation via Snap:
sudo apt install snapd
sudo snap install gdb --classic