20

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)

  • That's provided in Debian/testing, and as you see, involves changes to the runtime libraries. Someone might advise you how to do this as a Debian package, but the effect would be little different from switching to the testing configuration due to the large number of affected packages. – Thomas Dickey May 22 '16 at 20:41
  • Why do you specifically need the new ABI support? You can build most C++11 code with Debian 8's gcc 4.9.2, you'll just need to recompile it when Debian 9 is released. If you can't wait, the easiest solution would be to switch to testing, but that's probably not a good idea on a server (depending on what you mean by server of course). The switch from gcc 4.9 to gcc 5 involved a library transition, so you're in for a world of pain if you try to do it yourself! – Stephen Kitt May 22 '16 at 21:20
  • I agree with what thomas and stephen say, except I am far less worried about the idea of using testing on a server. Not all servers require long-term sameness of binaries and libraries (which is what "stable" means in debian context), for some servers tracking testing or even unstable is more useful (if, say, bleeding-edge features are needed, or just to keep ahead of the script kiddies). However, running testing/unstable on production servers absolutely requires a lot of skill with and knowledge about Debian to fix the occasional breakage. Test upgrades on other machines or VMs first. – cas May 23 '16 at 1:41
  • @cas I wasn't thinking of the stability of binaries, but rather the two main disadvantages of testing (used on its own): packages are sometimes temporarily removed (so the setup you just validated in your test VM may no longer be available easily), and security fixes can be delayed (sometimes for a long time if testing is undergoing a big library transition, although there is testing-security for such cases). – Stephen Kitt May 23 '16 at 4:43
  • 1
    If you recompile your program on the Debian system (instead of copying it over) it should work fine. – Stephen Kitt May 24 '16 at 6:07
12

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!

  • 1
    I have never tried this (nor do I wish to try it), but your procedure is interesting. Not many software suites are as tightly bound up with, and woven through, the entire Debian system as GCC. Does your procedure really work? Or does it cause more problems than it solves? Curious. – thb Sep 12 '16 at 0:35
  • 1
    I actually tried it with good results: I could successfully compile what I was building and the system continued to work with no problems.Nevertheless you might be right: changing the GCC version could break compiling other packages (ie compiling sources when installing packages with pip), but I think that this procedure is the least invasive because apt would keep track of which packages depends on GCC and will install compatible versions as needed (as far as I can remember). – llekn Sep 12 '16 at 20:27
  • 2
    Note for step 2: The file in /etc/apt/preferences.d/ should either not contain a dot "." in the file name, or end in ".pref". Otherwise, this file is ignored. An explanation of the meaning of value 100 and why it was chosen would be appreciated. – Ludwig Schulze Nov 22 '16 at 15:37
  • As I understand, the more Pin-Priority a package gets, the more preference it will get over other packages with a lower number. So, as in Debian's AptPrefences page states, testing by default gets Pin-Priority: 900 making all packages from testing to be installed by default. So, specifying that testing will have a Pin-Priority: 100 lowers testing packages priority making them installable only if requested when specifying the target at apt-get install -t testing ... – llekn Feb 2 '17 at 16:01
  • 1
    @LeeK-B Indeed, using Package: gcc upgrades the entire system to testing. The documentation about apt-prefences is confusing so I suppose this is what is happening: 1: As packages from testing have greater versions, by default they have precedence over standard ones 2: Specifying Package: gcc with Pin-priority: 100 makes all packages from testing to have default priority (higher than standard) except gcc. Exactly the opposite that we wanted. I updated the answer to avoid this mistake – llekn Mar 6 '17 at 15:47
6

To combine the 2 previous answers into one that works:

echo "deb http://ftp.us.debian.org/debian unstable main contrib non-free" >> /etc/apt/sources.list.d/unstable.list
apt-get update
apt-get install -t unstable gcc-5

BUT!!! Use this at your own risk as you are installing packages from unstable. You might also want to remove /etc/apt/sources.list.d/unstable.list once you have installed the packages.

If possible, install under Docker so you don't mess up your OS. Your mileage may vary.

4

As of 2017-02-19, gcc-5 has been removed from testing:

https://tracker.debian.org/pkg/gcc-5

You can apt-get install gcc-5 if you first execute this line as root:

echo "deb http://ftp.us.debian.org/debian unstable main contrib non-free" > /etc/apt/sources.list.d/unstable.list

Then, you will probably want to change the priority of that source in /etc/apt/preferences.d as per llekn's answer.

1

I was having problems last week; it looks like as of 2019-01-23 gcc-5 has been removed from the repositories completely. (See https://tracker.debian.org/pkg/gcc-5)

If you really need it I suppose you could compile it from source. I am going to find a way to drop the dependency from my system.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.