简体   繁体   中英

How to install gcc-9 on debian:latest docker

In order to use the C++17 include <filesystem> I need gcc-9 package in my debian docker.

By default debian:latest (aka 10 or buster) will install gcc 8.3.0 from the regular distro repo.

Is there any PPA, testing repo, whatever, where I can easily install a gcc-9 (or later) package (ie not build it from source)

Thanks !

note: need gcc-9 to have good C++17 <filesystem> support.
GCC 9 Release note:

Using the types and functions in does not require linking with -lstdc++fs now.

src: https://gcc.gnu.org/gcc-9/changes.html

note2: CMake 3.16* doesn't support any cxx_filesystem compiler feature AFAIK.

note3: you can found log here: https://github.com/Mizux/KalistoUnpacker/runs/642516660?check_suite_focus=true

From a fresh start of debian:10 :

echo 'deb http://deb.debian.org/debian testing main' > /etc/apt/sources.list.d/testing.list
apt update
cat <<EOF > /etc/apt/preferences.d/pin
Package: *
Pin: release a=stable
Pin-Priority: 700

Package: *
Pin: release a=testing
Pin-Priority: 650
EOF

apt install -qq -y -t testing build-essential

yields:

# g++ -v
gcc version 9.3.0 (Debian 9.3.0-11) 

In my Dockerfile I did:

FROM debian:latest AS env
...
RUN echo 'deb http://deb.debian.org/debian testing main' >> /etc/apt/sources.list
RUN apt update -y
RUN apt install -y gcc

note: I added these line after the install of build-essential so technically the container install the "default" gcc then it is updated by the one in the testing repo...

note2: Using RUN gcc --version I've got gcc (Debian 9.3.0-11) 9.3.0 :D

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM