Make sure wget, tar, and make are available
which wget tar make gcc g++
Download GCC source
cd ~
mkdir -p gcc_build
cd gcc_build
wget https://ftp.gnu.org/gnu/gcc/gcc-11.4.0/gcc-11.4.0.tar.gz
tar -xzf gcc-11.4.0.tar.gz
cd gcc-11.4.0
Download GCC prerequisites
./contrib/download_prerequisites
Create build directory (separate from source)
cd ..
mkdir gcc-build-11
cd gcc-build-11
Choose a custom installation path like ~/opt/gcc-11.4.0
../gcc-11.4.0/configure --prefix=$HOME/opt/gcc-11.4.0 \
--disable-multilib --enable-languages=c,c++
Build and install (may take 1–2 hours)
make -j$(nproc) # or a lower number if you hit memory limits
make install
Use your custom GCC
export PATH=$HOME/opt/gcc-11.4.0/bin:$PATH
export LD_LIBRARY_PATH=$HOME/opt/gcc-11.4.0/lib64:$LD_LIBRARY_PATH