Skip to content

Instantly share code, notes, and snippets.

@zuyu
Last active June 30, 2024 11:38
Show Gist options
  • Save zuyu/7d5682a5c75282c596449758d21db5ed to your computer and use it in GitHub Desktop.
Save zuyu/7d5682a5c75282c596449758d21db5ed to your computer and use it in GitHub Desktop.
Install gcc 6 on Ubuntu
sudo apt update && \
sudo apt install build-essential software-properties-common -y && \
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
sudo apt update && \
sudo apt install gcc-6 g++-6 -y && \
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-6 && \
gcc -v
@Manojbhat09
Copy link

Thanks

@luk0y
Copy link

luk0y commented Sep 3, 2020

Won't works with new dists

@MichaelZaidman
Copy link

Thanks, worked on Ubuntu 16.04

@goepp
Copy link

goepp commented Nov 30, 2020

Won't works with new dists

Same for me, on Ubuntu 20.04: installation of g++-6 throws the error E: Package 'g++-6' has no installation candidate.

@opptimus
Copy link

Won't works with new dists

Same for me, on Ubuntu 20.04: installation of g++-6 throws the error E: Package 'g++-6' has no installation candidate.

same for me,I can not install gcc-6 on ubuntu 20.04

@caesarhn
Copy link

Won't works with new dists

Same for me, on Ubuntu 20.04: installation of g++-6 throws the error E: Package 'g++-6' has no installation candidate.

same for me,I can not install gcc-6 on ubuntu 20.04
do you have solution ?

@Gideon-Felt
Copy link

Gideon-Felt commented Mar 13, 2021

I'm on 20.04 and get
E: Package 'gcc-6' has no installation candidate
E: Package 'g++-6' has no installation candidate

@goepp
Copy link

goepp commented Mar 14, 2021

The error message E: Package 'g++-6' has no installation candidate should come from the fact that after Ubuntu 16.04 LTS, the version of g++ is greater than 6 (g++-7 for 18.04 [source] and g++-9 for 20.04 source). The same remark goes for gcc.
A possible workaround would be to download the package source (link Download source package here) and install it from source.
I don't know what is the best way to install it from source though, especially for taking dependencies into account.

@androidyue
Copy link

I'm on 20.04 and get
E: Package 'gcc-6' has no installation candidate
E: Package 'g++-6' has no installation candidate

  1. sudo vim /etc/apt/sources.list
  2. add deb http://dk.archive.ubuntu.com/ubuntu/ bionic main universe to file
  3. sudo apt update
    4.sudo apt-get install gcc-6 g++-6 -y

@ququuy
Copy link

ququuy commented Jul 15, 2021

I'm on 20.04 and get
E: Package 'gcc-6' has no installation candidate
E: Package 'g++-6' has no installation candidate

  1. sudo vim /etc/apt/sources.list
  2. add deb http://dk.archive.ubuntu.com/ubuntu/ bionic main universe to file
  3. sudo apt update
    4.sudo apt-get install gcc-6 g++-6 -y

Thank you for solving out my problem~

@tavolivos
Copy link

I'm on 20.04 and get
E: Package 'gcc-6' has no installation candidate
E: Package 'g++-6' has no installation candidate

1. sudo vim  /etc/apt/sources.list

2. add `deb http://dk.archive.ubuntu.com/ubuntu/ bionic main universe` to file

3. sudo apt update
   4.sudo apt-get install gcc-6 g++-6 -y

This works perfectly

@Light--
Copy link

Light-- commented Feb 18, 2022

ubuntu 16.04 report error:

update-alternatives: error: alternative g++ can't be slave of gcc: it is a master alternative

@Yan-J-lee
Copy link

I'm on 20.04 and get
E: Package 'gcc-6' has no installation candidate
E: Package 'g++-6' has no installation candidate

1. sudo vim  /etc/apt/sources.list

2. add `deb http://dk.archive.ubuntu.com/ubuntu/ bionic main universe` to file

3. sudo apt update
   4.sudo apt-get install gcc-6 g++-6 -y

This really worked.
Thx for solving my problem!

@maitpate
Copy link

I am on I am on Ubuntu 22.04.2 , adding deb http://dk.archive.ubuntu.com/ubuntu/ bionic main universe` to the file is not working for me. Does any one know how to solve it ?

@pratt3000
Copy link

Same @maitpate

getting
E: Package 'gcc-6' has no installation candidate E: Package 'g++-6' has no installation candidate

@juangpc
Copy link

juangpc commented Mar 18, 2023

Hi,
This has been useful for me, so I'll chip in.
With ubuntu 20.04 you can't just add the ubuntu-toolchain repository.
sudo add-apt-repository ppa:ubuntu-toolchain-r/test won't work.
You'll get the error: Package gcc-6 is not available.
When you add deb http://dk.archive.ubuntu.com/ubuntu/ bionic main universe to sources.list you get a GPG error because a public encription key doesn't seem to be reachable.

To solve this issue, this is what worked on my fresh ubuntu 22.04 installation:

1. sudo vim  /etc/apt/sources.list
2. add `deb http://dk.archive.ubuntu.com/ubuntu/ bionic main universe` to file
3. sudo apt update
4. Find the key ID after the text: ```NO_PUBKEY``` XXXXXXXXXX
5. sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys XXXXXXXXXX
6. sudo apt update
7. sudo install gcc-6 g++-6 -y

Hope it helps (@pratt3000, @maitpate)

@MarcelMWS
Copy link

Hi, This has been useful for me, so I'll chip in. With ubuntu 20.04 you can't just add the ubuntu-toolchain repository. sudo add-apt-repository ppa:ubuntu-toolchain-r/test won't work. You'll get the error: Package gcc-6 is not available. When you add deb http://dk.archive.ubuntu.com/ubuntu/ bionic main universe to sources.list you get a GPG error because a public encription key doesn't seem to be reachable.

To solve this issue, this is what worked on my fresh ubuntu 22.04 installation:

1. sudo vim  /etc/apt/sources.list
2. add `deb http://dk.archive.ubuntu.com/ubuntu/ bionic main universe` to file
3. sudo apt update
4. Find the key ID after the text: ```NO_PUBKEY``` XXXXXXXXXX
5. sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys XXXXXXXXXX
6. sudo apt update
7. sudo apt install gcc-6 g++-6 -y

Hope it helps (@pratt3000, @maitpate)

Thanks it works 👍

I moved/renamed them (for my makefile):

8.(optional) sudo mv /usr/bin/g++-6 /usr/bin/g++
9.(optional) sudo mv /usr/bin/gcc-6 /usr/bin/gcc 

@CallShaul
Copy link

I'm on 20.04 and get
E: Package 'gcc-6' has no installation candidate
E: Package 'g++-6' has no installation candidate

1. sudo vim  /etc/apt/sources.list

2. add `deb http://dk.archive.ubuntu.com/ubuntu/ bionic main universe` to file

3. sudo apt update
   4.sudo apt-get install gcc-6 g++-6 -y

This really worked. Thx for solving my problem!

Worked like a charm (on Kub20) thanks !

@moontome
Copy link

moontome commented Aug 8, 2023

I'm on 20.04 and get
E: Package 'gcc-6' has no installation candidate
E: Package 'g++-6' has no installation candidate

1. sudo vim  /etc/apt/sources.list

2. add `deb http://dk.archive.ubuntu.com/ubuntu/ bionic main universe` to file

3. sudo apt update
   4.sudo apt-get install gcc-6 g++-6 -y

this is showing me
sudo: vim: command not found

@Biloot
Copy link

Biloot commented Nov 1, 2023

This is showing me
sudo: vim: command not found

vim is just a text editor. You can whether install it using sudo apt install vim or use another one, as nano.

@rashikshrestha
Copy link

Hi, This has been useful for me, so I'll chip in. With ubuntu 20.04 you can't just add the ubuntu-toolchain repository. sudo add-apt-repository ppa:ubuntu-toolchain-r/test won't work. You'll get the error: Package gcc-6 is not available. When you add deb http://dk.archive.ubuntu.com/ubuntu/ bionic main universe to sources.list you get a GPG error because a public encription key doesn't seem to be reachable.

To solve this issue, this is what worked on my fresh ubuntu 22.04 installation:

1. sudo vim  /etc/apt/sources.list
2. add `deb http://dk.archive.ubuntu.com/ubuntu/ bionic main universe` to file
3. sudo apt update
4. Find the key ID after the text: ```NO_PUBKEY``` XXXXXXXXXX
5. sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys XXXXXXXXXX
6. sudo apt update
7. sudo install gcc-6 g++-6 -y

Hope it helps (@pratt3000, @maitpate)

Thanks for the solution. When I tried, dk.archive.ubuntu was unreachable, so I used en.archive.ubuntu instead.

@chengyiqiu1121
Copy link

Hi, This has been useful for me, so I'll chip in. With ubuntu 20.04 you can't just add the ubuntu-toolchain repository. sudo add-apt-repository ppa:ubuntu-toolchain-r/test won't work. You'll get the error: Package gcc-6 is not available. When you add deb http://dk.archive.ubuntu.com/ubuntu/ bionic main universe to sources.list you get a GPG error because a public encription key doesn't seem to be reachable.

To solve this issue, this is what worked on my fresh ubuntu 22.04 installation:

1. sudo vim  /etc/apt/sources.list
2. add `deb http://dk.archive.ubuntu.com/ubuntu/ bionic main universe` to file
3. sudo apt update
4. Find the key ID after the text: ```NO_PUBKEY``` XXXXXXXXXX
5. sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys XXXXXXXXXX
6. sudo apt update
7. sudo install gcc-6 g++-6 -y

Hope it helps (@pratt3000, @maitpate)

Thank you! It's helpful😺

@AtoshDustosh
Copy link

I'm on 20.04 and get
E: Package 'gcc-6' has no installation candidate
E: Package 'g++-6' has no installation candidate

  1. sudo vim /etc/apt/sources.list
  2. add deb http://dk.archive.ubuntu.com/ubuntu/ bionic main universe to file
  3. sudo apt update
    4.sudo apt-get install gcc-6 g++-6 -y

It worked!. Thank you so much.

@Zetacat
Copy link

Zetacat commented May 23, 2024

I'm on 20.04 and get
E: Package 'gcc-6' has no installation candidate
E: Package 'g++-6' has no installation candidate

  1. sudo vim /etc/apt/sources.list
  2. add deb http://dk.archive.ubuntu.com/ubuntu/ bionic main universe to file
  3. sudo apt update
    4.sudo apt-get install gcc-6 g++-6 -y

for those who encounter the error:

E: The repository 'http://dk.archive.ubuntu.com/ubuntu bionic InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.

consider adding [trusted=yes]:

deb [trusted=yes] http://dk.archive.ubuntu.com/ubuntu/ bionic main universe

After that, I can install them successfully~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment