Debian – How to install GCC 5 on debian jessie 8.1

cdebiang++gcc

I tried many solutions to install update for my gcc compiler on debian server. None of them worked. I need the compiler update to use new features of c++11, as this provides a stable libcxx11 ABI, and stable support for C++11 (refer here). Specifically getting version `GLIBCXX_3.4.21' which is not included in my current compiler gcc version 4.9.2 (Debian 4.9.2-10).

Some pointers to solution will be helpful. Thanks in advance.

Some links to forum related to my issue which I already tried:

1
2
3 (not entirely related solution is for ubuntu, but I couldn't find gcc-5 in ftp server of debian yet)

Best Answer

I needed GCC 5+ installed on debian jessie and, as is available for debian testing (at least on jun-16) you can use apt-pinning to install packages available there (see https://wiki.debian.org/AptPreferences).

To install GCC 5+ from testing on debian jessie using apt-pinning:

  1. Add debian testing repo to your apt sources by creating a file in the directory /etc/apt/sources.list.d containing the line

    deb http://ftp.us.debian.org/debian testing main contrib non-free

  2. Instruct debian to use testing sources on certain packages by creating a file in /etc/apt/preferences.d containing the following:

    Package: *
    Pin: release a=testing
    Pin-Priority: 100
    
  3. Update apt database: sudo apt-get update

  4. Install gcc from testing: sudo apt-get install -t testing gcc

    Note that using -t testing you tell apt-get to install gcc from testing sources as configured earlier.

I strongly suggest to clean any compilation and re-compile any dependency before compiling your sources again.

Have fun!