Discussions

Installing gcc error
apt update; apt upgrade More on reddit.com
๐ŸŒ r/bashonubuntuonwindows
3
5
April 21, 2021
Can't install GCC in Ubuntu 20.04 WSL - Stack Overflow
Setting up gcc (4:9.3.0-1ubuntu2) ... package post-installation script subprocess returned error exit status 2 Errors were encountered while processing: gcc E: Sub-process /usr/bin/dpkg returned an error code (1) ... sudo dpkg --purge --force-depends gcc sudo apt-get autoremove ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
error while installing gcc on ubuntu 14.04.3 - Stack Overflow
I recently installed Ubuntu and I want to start coding in C and C++. I have gdb and gcc files on my desktop. I am getting this error while trying to install the above: soumya@soumya-VirtualBox:~/ More on stackoverflow.com
๐ŸŒ stackoverflow.com
linux - how to install gcc-12 on ubuntu - Stack Overflow
Step 3: installing GCC prequisites and run configure again ยท The missing libraries will be shown in above ./confgiure output, search and install them one by one. $ apt-cache search MPFR $ sudo apt-get install libmpfrc++-dev $ apt-cache search MPC | grep dev $ sudo apt-get install libmpc-dev ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Reddit
reddit.com โ€บ r/bashonubuntuonwindows โ€บ installing gcc error
r/bashonubuntuonwindows on Reddit: Installing gcc error
April 21, 2021 -

I tried to install gcc in Ubuntu on WSL2 and get the following error,

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/l/linux/linux-libc-dev_5.4.0-54.60_amd64.deb 404 Not Found [IP: 91.189.88.152 80]

E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

Please help me fix this.

๐ŸŒ
GitHub
gist.github.com โ€บ zuyu โ€บ 7d5682a5c75282c596449758d21db5ed
Install gcc 6 on Ubuntu ยท GitHub
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.
Top answer
1 of 2
121

Is GCC-4.8 available for 12.04 Precise now?

Update: As of 6/05/2013, there is currently a release of gcc 4.8.1 for 12.04(precise) available at https://launchpad.net/~ubuntu-toolchain-r/+archive/test.

The short answer is: gcc-4.8 is currently available for 12.04(Precise) via the toolchain PPA or by compiling the source(see below for details).

Release Announcement

The announcement for the release of gcc-4.8 was made on March 22nd, so you probably won't be seeing this in an official repository just yet.

However, it appears that Launchpad does have a PPA available for the toolchain test builds that does include gcc-4.8, here: https://launchpad.net/~ubuntu-toolchain-r/+archive/test

According to the changelog and package list, there are debs for i386, amd64, arm, and powerpc and were built against raring 13.04.

The latest available version of gcc, for 12.04, is 4.8.1 and is available in the toolchain PPA.

Adding the toolchain/test PPA:

To add the PPA to your system, open a terminal(Ctrl+Alt+t) and run the following commands:

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50

You will also be prompted to install a number of suggested packages. These packages are recommended, but optional, for the installation of gcc-4.8.

  • What are PPAs and how do I use them?
  • Are PPA's safe to add to my system and what are some "red flags" to watch out for?

What C++ features are available in gcc-4.8 that are not available in gcc-4.7.2?

  • According to GNU.ORG, gcc-4.7, supports a number of C++11 features.
  • As of the gcc-4.8 release, gcc-4.7 does not support 8 out of 64 features (See C++0x/C++11 Support in GCC)

  • These features are:

    Language Features
    - Rvalue references for *this
    - Generalized attributes
    - Alignment support
    - Inheriting constructors
    Concurreny
    - Bidirectional Fences
    - Memory model
    - Abandoning a process and at_quick_exit
    - Thread-local storage 
    
  • For a full list of changes in gcc-4.8, see the Changelist

I need these gcc features on 12.04 Precise, now. How can I get them?

Building GCC-4.8 from source:

If you need gcc-4.8 on 12.04 now, your only option is to build it from source.

Please read the GCC installation FAQ prior to installation.

You can download gcc-4.8 from one of gnu.org's mirror sites or directly from their SVN server.

Here is an example of steps to compile from source (see here for additional details.) Note that these may vary depending on your system and preferences.

  1. Download the source code

    • Make a build directory ( mkdir gcc-build && cd gcc-build)
    • Download the source file: wget http://www.netgull.com/gcc/releases/gcc-4.8.0/gcc-4.8.0.tar.bz2 (adjust this command to use an appropriate mirror site.
    • Unzip the file (tar -xvjf <file name>)
  2. Install some additional libraries (sudo apt-get install libgmp-dev libmpfr-dev libmpc-dev libc6-dev)

  3. Compile the source: ./gcc-4.8.0/configure --prefix=/app/gcc/4.8.0
  4. Run make (This will take some time to complete. Go make some coffee, or bake some cookies. ;-))
  5. Install the code: sudo make install

Once this process has completed, run the command gcc --version to verify that the installation has completed successfully. You should see something similar to the following output:

maggotbrain@foucault:~$ gcc --version
gcc (Linaro 4.8.0) 4.8.0
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

The bottom line: Thank all those folks who provide easy to install Ubuntu backports for you. Give them some of the cookies that you baked while running make. ;-)

2 of 2
1

So answer above works, at least for manual install. Though even after sudo make install, running gcc still just runs the stock version 4.6.3. Even trying gcc-4.8 or gcc-4.8.0 doesn't work. Running /app/gcc/4.8.0/bin/gcc appears to be the only thing that works for me. I mean it is kind of lame but at least it works.

Find elsewhere
๐ŸŒ
GitHub
gist.github.com โ€บ jlblancoc โ€บ 99521194aba975286c80f93e47966dc5
Installing gcc-7 & g++-7 in Ubuntu 16.04LTS Xenial ยท GitHub
$ sudo apt install build-essential or $ sudo apt install gcc ... have you solved the issue above? I am trying to install rtx 2080 ti and nvidia driver also shows cc version check failure. I have to install gcc 7.3. instead of 7.4 but I dont know how ... Thanks! It worked and only got an error for g++ update-alternatives: error: alternative g++ can't be slave of gcc: it is a master alternative.
Top answer
1 of 1
4

As some comments have already pointed out, gcc is part of the main ubuntu repository. So technically, there should be a package gcc. You can search for all the packages that are available by running the command

apt-cache search gcc

This will show all packages that have gcc in their name (and that will likely be very many). You can narrow down the search to packages that start with gcc and then have a space (in other words, the package that really is called gcc),

apt-cache search gcc | grep "^gcc[[:space:]]"

If the former command found packages such as gcc-8 or similar, but the latter command didn't show anything, then it is likely that your package management doesn't know about gcc. Some comments have also suggested to update the package database by running

sudo apt-get update

This is generally a good idea before you install packages, because the installation will attempt to download whatever you try to install and that download may fail if (for example) the location of the package has changed. The command apt-get update makes sure everything is in the right place so that things can be found when you want to install them.

If after updating your package database (by apt-get update), you still don't find a package called gcc, but you do find one with a specific version number, the simplest way to get you a working gcc on your computer is probably to settle for a specific version, such as for example by running

sudo apt-get install gcc-7

You may have seen that some comments have pointed out that gcc would normally be part of an ubuntu installation. So the errors you are reporting might point at some more intricate problem with they way your package database is configured. If you are on a freshly installed ubuntu system, the simplest way to fix this is to simply re-install your system while you have a solid internet connection. If you are not on a freshly installed ubuntu system, things can be a bit more involved, but they are quite well documented if you search for ways to fix your /etc/apt/sources.list file.

๐ŸŒ
Super User
superuser.com โ€บ questions โ€บ 1389166 โ€บ unable-to-install-gcc-in-ubuntu-terminal
Unable to Install gcc in Ubuntu Terminal - Super User
Those are network connectivity errors. I'd change your hosts to your country specific ones or a close to you (network wise) mirror. I like educational institutions that are geographically close to me. https://launchpad.net/ubuntu/+archivemirrors ...
๐ŸŒ
Linuxize
linuxize.com โ€บ home โ€บ gcc โ€บ how to install gcc compiler on ubuntu 18.04
How to Install GCC Compiler on Ubuntu 18.04 | Linuxize
October 31, 2019 - In the following example, we will install the latest three versions of GCC and G++. First, add the ubuntu-toolchain-r/test PPA to your system with: ... The commands below will configure alternative for each version and associate a priority with it. The default version is the one with the highest priority, in our case that is gcc-9. ... sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 90 --slave /usr/bin/g++ g++ /usr/bin/g++-9 --slave /usr/bin/gcov gcov /usr/bin/gcov-9 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 80 --slave /usr/bin/g++ g++ /usr/bin/g++-8 --slave /usr/bin/gcov gcov /usr/bin/gcov-8 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 70 --slave /usr/bin/g++ g++ /usr/bin/g++-7 --slave /usr/bin/gcov gcov /usr/bin/gcov-7
๐ŸŒ
LinuxCapable
linuxcapable.com โ€บ home โ€บ ubuntu โ€บ how to install gcc on ubuntu 26.04, 24.04 and 22.04
How to Install GCC on Ubuntu 26.04, 24.04 and 22.04 - LinuxCapable
1 week ago - Install build-essential to get ... to locate package gcc-14โ€ or a similar error, first confirm that the requested branch exists for your Ubuntu release....
Top answer
1 of 4
50

gcc-12 is not available in ubuntu 20.04, so we need to compile it from source code, here are the steps which I borrowed from this video:

  • Step 1: clone gcc source code and checkout gcc-12 branch
$ git clone https://gcc.gnu.org/git/gcc.git gcc-source
$ cd gcc-source/
$ git branch -a
$ git checkout remotes/origin/releases/gcc-12
  • Step 2: make another build dir

Note this is important as running ./configure from within the source directory is not supported as documented here.

$ mkdir ../gcc-12-build
$ cd ../gcc-12-build/
$ ./../gcc-source/configure --prefix=$HOME/install/gcc-12 --enable-languages=c,c++
  • Step 3: installing GCC prequisites and run configure again

The missing libraries will be shown in above ./confgiure output, search and install them one by one.

$ apt-cache search MPFR
$ sudo apt-get install libmpfrc++-dev
$ apt-cache search MPC | grep dev
$ sudo apt-get install libmpc-dev
$ apt-cache search GMP | grep dev
$ sudo apt-get install libgmp-dev
$ sudo apt-get install gcc-multilib
$ ./../gcc-source/configure --prefix=$HOME/install/gcc-12 --enable-languages=c,c++

An alternative is to run the download_prerequisites script.

$ cd ../
$ cd gcc-source/
$ ./contrib/download_prerequisites
$ ./../gcc-source/configure --prefix=$HOME/install/gcc-12 --enable-languages=c,c++
  • Step 4: compile gcc-12
$ make -j16

Still flex is missing:

$ sudo apt-get install flex
$ ./../gcc-source/configure --prefix=$HOME/install/gcc-12 --enable-languages=c,c++
$ make -j16
$ make install

Another way is to use Ubuntu 22.04 where gcc-12 is available. In Ubuntu 22.04, gcc-12 can be installed with apt:

$ sudo apt install gcc-12
2 of 4
16

You can use Homebrew to install pre-built binaries. Follow instructions to install Homebrew at https://brew.sh/, then

brew install gcc for default GCC (currently 11) or brew install gcc@12 for gcc-12.

Note that it may compile missing dependencies.

Top answer
1 of 3
7

To install gcc-7 on ubuntu you should use this ppa:

sudo add-apt-repository ppa:jonathonf/gcc
sudo apt-get update

Then run: apt-cache search gcc-7

sample output :

gcc-7-base - GCC, the GNU Compiler Collection (base package)
gcc-7 - GNU C compiler
gcc-7-multilib - GNU C compiler (multilib support)
gcc-7-plugin-dev - Files for GNU GCC plugin development.
gcc-7-test-results - Test results for the GCC test suite
lib32gcc-7-dev - GCC support library (32 bit development files)
libgcc-7-dev - GCC support library (development files)
gcc-7-doc - Documentation for the GNU compilers (gcc, gobjc, g++)
gcc-7-hppa64-linux-gnu - GNU C compiler (cross compiler for hppa64)
gcc-7-locales - GCC, the GNU compiler collection (native language support files)
gcc-7-source - Source of the GNU Compiler Collection
libx32gcc-7-dev - GCC support library (x32 development files)
gcc-7-offload-nvptx - GCC offloading compiler to NVPTX
lib64gcc-7-dev - GCC support library (64bit development files)

Install gcc-7:

sudo apt install gcc-7
2 of 3
2

If you need to setup a test rig with the compiler, then Fedora 26 ships with GCC 7.1.

You can also find GCC 7 in Debian 10/Buster (Debian 9 with Testing repo enabled). For Debian, you must apt-get install gcc-7 g++-7.

For completeness, its not clear which version of the Microsoft compilers support C++17 and std::byte (the reason I needed the compiler for testing).

And thanks to GAD3R for his help. The reason I avoided it was I could not establish provenance for some of the PPAs.