8

This question appears to be addressed properly in several questions and other places easily found with Google, but I don't find the solution satisfactory for the reasons explained below. But just for completion, I've included some relevant links:

https://askubuntu.com/questions/138284/how-to-downgrade-a-package-via-apt-get https://askubuntu.com/questions/428772/how-to-install-specific-version-of-some-package/428778 https://askubuntu.com/questions/26498/choose-gcc-and-g-version ...

And others.

However, this question is regarding installing a very specific version of GCC in Kali Linux, which does not appear readily available as a specific package. In particular, the question is regarding how to install version 6.3.0, as I need this version to compile a particular program: https://www.reddit.com/r/Monero/comments/6d0ah8/xmrig_miner_new_release/

(as a bonus question, if there is a more sane way to fix this particular issue without using a different version of GCC, feel free to answer, but I believe this question is general and I would like to know how to do it regardless of how to make the aforementioned program link correctly)

The versions which are available to install of any package, e.g. gcc, can be determined with:

apt-cache showpkg gcc

Which will list the available versions under "versions:", e.g.

4:7.2.0-1d1
4:4.9.2-2

Installation is then as simple as issuing

apt-get install gcc:4:4.9.2-2

This will install the older version 4:4.9.2-2, by simply (I believe) overwriting the 7.2.0-1d1 install, if present.

To get version 4:4.9.2-2 available at all, I had to add deb http://old.kali.org/kali sana main non-free contrib to my /etc/apt/sources.list file and then run apt-get update.

However, what if the version I need is not listed?

I've been experimenting with various sources, e.g. those found here: http://snapshot.debian.org/ and at various other questions and websites from Google searches.

Most of them give me ignore or errors, e.g. as follows

Ign:3 http://snapshot.debian.org/archive/debian/20091004T111800Z lenny InRelease

Even if this would work, it seems to be a very bad approach to get a particular version installed, as adding some arbitrary source might not have the particular version I want.

If I search on snapshot.debian.org for gcc, I get only very old versions: http://snapshot.debian.org/package/gcc/

I eventually became frustrated with this approach and compiled GCC 6.3.0 from the source tarball. The compilation was successful, but then I'm faced with how to install it. I'm cautious about running make install as I fear it will tamper with apt and dpkg and possibly break the system.

Instead, I attempted to run it from the build directory, directly. I tried to simply add the build directory as the first entry in my PATH, which didn't work. Then, I attempted to rename /usr/bin/gcc and do a symlink from /usr/bin/gcc to where my gcc-6.3.0 executable lives. This presents the following problem:

cc: error trying to exec 'cc1': execvp: No such file or directory, which

This was fixed with another entry in my PATH.

Then, I get this error:

/usr/include/stdio.h:34:21: fatal error: stddef.h: No such file or directory

Which I assume is because of a missing entry in /usr/lib/gcc/x86_64-linux-gnu. I tried to make a symlink from 6 to 6.3.0, but this wasn't sufficient. I also tried to actually copy everything with cp -R, same result.

This should be a 64-bit program, but I also considered the same for /usr/lib/gcc/i686-linux-gnu.

I'm sure I could start doing strace to see where it attempts to open the files from, read log files, read the source, and eventually I imagine I'd be able to figure out how to hack together a poorly conceived solution. But it would be nice if someone could tell me how to do this in a sane manner.

  • This doesn’t detract from the general merits of your question; but current releases of XMRig should build fine with GCC 7, so you should just be able to build it without messing around with GCC 6.3. – Stephen Kitt Dec 14 '17 at 8:31
  • You can always compile GCC (any not too ancient version) from its source code, since it is free software. Be careful when configuring it, and build it outside of its source tree. – Basile Starynkevitch Dec 15 '17 at 9:24
10

How to install a specific version of GCC in Kali Linux?

GCC 6 is available on kali linux it can be installed as follow :

apt install g++-6 gcc-6

To switch between gcc6 and gcc7

update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 1 --slave /usr/bin/g++ g++ /usr/bin/g++-7
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 2 --slave /usr/bin/g++ g++ /usr/bin/g++-6
update-alternatives --config gcc

sample output:

There are 2 choices for the alternative gcc (providing /usr/bin/gcc).

  Selection    Path            Priority   Status
------------------------------------------------------------
* 0            /usr/bin/gcc-6   2         auto mode
  1            /usr/bin/gcc-6   2         manual mode
  2            /usr/bin/gcc-7   1         manual mode

Press <enter> to keep the current choice[*], or type selection number:

Select your default gcc version.

on 2017-08-05 the gcc-6 version is upgraded from 6.3.0 to 6.4.0 .

Installing xmrig following the build's instructions.

apt-get install git build-essential cmake libuv1-dev libmicrohttpd-dev
git clone https://github.com/xmrig/xmrig.git
cd xmrig
mkdir build
cd build
cmake ..
make

Building a specific gcc version 6.3.0

Download the tarball from the closest mirror : GCC Releases

wget https://ftp.gnu.org/gnu/gcc/gcc-6.3.0/gcc-6.3.0.tar.bz2
tar xvf gcc-6.3.0.tar.gz
cd gcc-6.3.0
apt build-dep gcc
./contrib/download_prerequisites
cd ..
mkdir objdir
cd objdir
$PWD/../gcc-6.3.0/configure --prefix=/usr/bin/gcc-6.3 --enable-languages=c,c++,fortran,go --disable-multilib
make -j 8
make install

Add gcc-6.3 to update-alternatives

Important : The --disable-multilib option is required to configure and build gcc for the current architecture.

GCC WIKI : Installing GCC

  • 1
    Forgive me, but doesn't this install whatever version of GCC that "gcc-6" provides? What if I want to install specifically 6.3.0? – AlphaCentauri Dec 14 '17 at 14:07
  • @AlphaCentauri 6 months ago the available gcc6 version is 6.3.0 , now the gcc6 version is upgraded to 6.4.0 . – GAD3R Dec 14 '17 at 16:23
  • 1
    @AlphaCentauri answer updated including the building steps. – GAD3R Dec 15 '17 at 8:59
1
  1. First you have to go to this website : http://gcc.gnu.org/mirrors.html
  2. Then select old-releases and you will see different versions.
  3. Now you should click in the one that you want to have and the download will start.

  4. Finally, you have to compile and install from source: https://askubuntu.com/questions/25961/how-do-i-install-a-tar-gz-or-tar-bz2-file

  • 1
    Thanks, but I don't believe you've read my whole question. I pointed out how I have attempted to compile from source. The problem with this (as pointed out in my question), is that doing "make install" on GCC might not be a good idea as it might possibly break the system. Furthermore, simply running GCC without doing make install introduces its own challenges, which I've also outlined in my original question. – AlphaCentauri Dec 14 '17 at 12:46
  • You have stated in your question that make install might tamper with dpkg or apt.. can you elaborate! @AlphaCentauri – Prashant Luhar Dec 14 '17 at 18:08
0

If you did a standard ./configure; make without passing any options to configure, then make install will place the pieces of your desired version of GCC in various subdirectories of /usr/local.

The /usr/local directory tree is intended for software installed by the system administrator outside of the package-management system (ie. exactly what you're doing). As such, software installed there will not break packaged software except in extremely unusual circumstances.

GCC in particular is designed around the assumption that you'll have multiple versions installed. It pretty much requires active measures on your part to break anything (eg. by mixing and matching pieces to try to create a hybrid version).

  • You should not (and probably won't succeed in) building GCC in its source tree. And you probably want additional options to its configure script (e.g. some -program-suffix= etc) – Basile Starynkevitch Dec 15 '17 at 9:28
0

I eventually became frustrated with this approach and compiled GCC 6.3.0 from the source tarball. The compilation was successful,

First, I would recommend, if you compile GCC from its source, to choose a more recent version (e.g. GCC 7 at end of 2017).

Then, be sure to build GCC outside of its source tree and to try first its configure script with --help and to pass more options to its configure. Read carefully the GCC installation instructions and understand the role of autoconf.

In practice, I recommend

  • run /usr/bin/gcc -v to understand how your system's GCC has been configured

  • run apt-get build-dep gcc-6 (or similar) to get recent system's GCC dependencies

  • create a build directory outside of your GCC source tree, and run further .../configure (replace ... by appropriate relative path, e.g. ../gcc-7.2/) and make there.

  • you probably want to pass at least --program-suffix=-mine to that configure (the -mine can be replaced by another suffix) and you might even add --prefix=$HOME/soft/ if you don't have root access. You'll probably want additional options to configure and you need to choose and give them carefully.

  • then a later make install (you could even run without being root make install DESTDIR=/tmp/gccinst/ and later copy carefully and recursively as root that /tmp/gccinst/ ....) would install things in /usr/local/bin/gcc-mine etc.... (or $HOME/soft/bin/gcc-mine ....) so won't break any system installed files.

Notice that the FHS requires the package management system to leave alone /usr/local/ (which is the default --prefix for GCC's configure)

  • The OP already has GCC 7, but was looking for 6.3.0 following a misguided reddit comment. – Stephen Kitt Dec 15 '17 at 11:59
0

You can also use a precompiled toolchain or this one for your specific architecture (x86_64, glibc, gcc 6.3).

Of course next option is to use a so called rootfs-builder like buildroot or yocto
to generate a toolchain with your specfic gcc version.

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.