skip to Main Content

I am trying to install gcc13 and g++13 in the following Rust docker image.

# Builder
FROM rust:1-bookworm AS builder

RUN apt update
RUN apt install software-properties-common -y
RUN apt-get install python3-launchpadlib -y
RUN add-apt-repository ppa:ubuntu-toolchain-r/test -y
RUN apt update
RUN apt install -y clang g++-13 gcc-13

Since gcc13 is not natively available in debian bookworm, I already tried using method like using ppa:ubuntu-toolchain-r/test as describe here.

However, I’m still getting the error E: Unable to locate package g++-13 and E: Unable to locate package g++-13. Any ideas what I have done wrong?

2

Answers


  1. Option 1: Alpine

    You can use an Alpine base image.

    FROM rust:1-alpine
    
    RUN apk add g++
    

    In this case you’ll immediately have access to GCC 13.

    / # gcc -v
    gcc version 13.2.1 20231014 (Alpine 13.2.1_git20231014) 
    / # g++ -v
    gcc version 13.2.1 20231014 (Alpine 13.2.1_git20231014)
    

    Option 2: Install onto Debian

    If you really want an image based on Debian Bookworm then you can install GCC 13 from source. It’s a bit of a slog because the build takes a while.

    FROM rust:1-bookworm AS builder
    
    RUN apt-get update && 
        apt-get install -y 
            build-essential 
            wget 
            libgmp-dev 
            libmpfr-dev 
            libmpc-dev
    
    RUN wget -q https://ftp.gnu.org/gnu/gcc/gcc-13.2.0/gcc-13.2.0.tar.gz
    RUN tar -xf gcc-13.2.0.tar.gz && 
        cd gcc-13.2.0 && 
        ./contrib/download_prerequisites
    
    # This will cross-compile using the existing GCC on the image.
    RUN cd gcc-13.2.0 && 
        ./configure --disable-multilib --enable-languages=c,c++ && 
        make -j$(nproc) && 
        make install
    
    RUN update-alternatives 
            --install /usr/bin/gcc gcc /usr/local/bin/gcc 60 
            --slave /usr/bin/g++ g++ /usr/local/bin/g++ && 
        rm -rf gcc-13.2.0.tar.gz gcc-13.2.0 && 
        apt purge -y gcc cpp
    
    Login or Signup to reply.
  2. For those who are trying to install gcc13 and g++13 in Debian 12, try to download the tar.gz file and extract it

    https://gcc.gnu.org/pub/gcc/releases/gcc-13.2.0/

    Run the following commands inside of the extracted folder:

    ./contrib/download_prerequisites
    ./configure --disable-multilib --enable-languages=c,c++
    make -j3
    sudo update-alternatives --install /usr/bin/gcc gcc /usr/local/bin/gcc 60 --slave /usr/bin/g++ g++ /usr/local/bin/g++
    

    If you type g++ --version, it should look like this

    g++ (GCC) 13.2.0
    Copyright (C) 2023 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.
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search