Ubuntu 18.10 - how to install a specific version of gcc

11,206

Solution 1

You need to use the equals sign instead of the colon.

sudo apt-get install gcc=4:8.2.0-1ubuntu1

You'll also need to update your default gcc config.

How to change the default GCC compiler in Ubuntu?

Solution 2

I wanted to install gcc-6 alongside my existing installation of gcc-9 and this is how I did it. First off, sudo apt install gcc-6 didn't work because the package wasn't found so I had to add a new repository that contained gcc-6. To do this, I first found a repository that contains gcc-6 from Google and ended up at: https://packages.ubuntu.com/bionic/gcc-6

From there, I chose an architecture (amd64) which took me to a page with all the mirrors. I added the first mirror (mirrors.kernel.org/ubuntu) to /etc/apt/sources.list and did sudo apt update and then installed gcc-6 with sudo apt install gcc-6.

To switch between gcc versions, I used the following:

sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 6
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 9

sudo update-alternatives --config g++
Share:
11,206

Related videos on Youtube

Not a machine
Author by

Not a machine

Updated on June 04, 2022

Comments

  • Not a machine
    Not a machine almost 2 years

    Disclaimer: I have searched and read similar posts and they do not answer my question.

    I am running Ubuntu 18.10 and need to install gcc 8.2.0 to build kernel modules. apt-get wants to install 8.3 which doesn't match how my kernel was built.

    I have tried

    sudo apt-get update
    sudo apt-get install gcc:8.2.0
    

    but I get the error message that the package could not be found.

    I tried going the route of installing 8.3 and then building 8.2.0 and installing it into /usr/local/bin. It worked for a few modules but when I tried building kernel modules for VMWare it complained that the package was not installed correctly. I am a CentOS guy so a little out of my element on debian based distros.

    I located gcc 8.2.0 here as part of the core for Cosmic (18.10) but I am unsure how to install it.

    I also tried:

    sudo apt-get install gcc=4:8.2.0-1ubuntu1 --no-upgrade
    

    and it still wants to install 8.3. Do I need to change the defaults for this to work? It completely ignores the --no-upgrade option.

    • Not a machine
      Not a machine almost 5 years
      I have pretty much determined that what I want to do is not possible. I downloaded the 8.2.0 package and attempted to install it locally. It complains that 8.3 is to be installed. How Ubuntu expects developers to be able to build kernel modules with the compiler used to build the kernel is a mystery. Time to find another distro.
  • Not a machine
    Not a machine almost 5 years
    See my new comments in OP.
  • Not a machine
    Not a machine almost 5 years
    I can set my default gcc to 8.2.0 when 8.3 is installed as per the link you provided but that won't help if I cannot get 8.2.0 installed.
  • Not a machine
    Not a machine over 3 years
    Kudos on getting both installed at the same time. It should be possible to invoke the correct compiler version simply using the appropriate path. It seems cumbersome to need to set update alternatives to execute a different version. Or, am I misreading your post?
  • Michael Kiros
    Michael Kiros over 3 years
    It probably is but I haven't tried that approach. With update-alternatives I had to set it up once with --install then I can now switch between the different versions with the --config option. I didn't think it was too much but if you don't like it I'm sure you can set up the correct paths and execute a specific g++/gcc version.