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
@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