Issue
I just installed gcc-8.1 from source using those steps:
wget https://ftp.gnu.org/gnu/gcc/gcc-8.1.0/gcc-8.1.0.tar.gz
tar xvf gcc-8.1.0.tar.gz
cd gcc-8.1.0
apt build-dep gcc
./contrib/download_prerequisites
cd ..
mkdir objdir
cd objdir
$PWD/../gcc-8.1.0/configure --prefix=/usr/bin/gcc-8.1 --enable-languages=c,c++,fortran,go --disable-multilib
make -j8
make install
Everything is correct?
Then I add it to update-alternatives
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8.1 60 --slave /usr/bin/g++ g++ /usr/bin/g++-8.1
There are 3 choices for the alternative gcc (providing /usr/bin/gcc).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/gcc-7 60 auto mode
1 /usr/bin/gcc-5 60 manual mode
* 2 /usr/bin/gcc-7 60 manual mode
3 /usr/bin/gcc-8.1 60 manual mode
Press <enter> to keep the current choice[*], or type selection number: 3
update-alternatives: using /usr/bin/gcc-8.1 to provide /usr/bin/gcc (gcc) in manual mode
update-alternatives: warning: skip creation of /usr/bin/g++ because associated file /usr/bin/g++-8.1 (of link group gcc) doesn't exist
My issue is when I type gcc -v
, it said bash: /usr/bin/gcc: Is a directory
Solution
--prefix=/usr/bin/gcc-8.1
means that everything that is part of the installation will be placed in the /usr/bin/gcc-8.1/
directory.1
This means that your actual GCC binary is probably located at /usr/bin/gcc-8.1/bin/gcc
(or some similarly-named executable, maybe it is actually called gcc-8
or gcc-8.1
).
When you set the GCC binary to /usr/bin/gcc-8.1
using update-alternatives
, you set the symlink that is normally used to resolve which GCC binary you want to a directory - resulting in the error that you are now getting.
To fix this issue, follow these steps:
Remove the wrong entry in
update-alternatives
:update-alternatives --remove gcc /usr/bin/gcc-8.1
Add the right entry.2
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8.1/bin/gcc 60 \ --slave /usr/bin/g++ g++ /usr/bin/gcc-8.1/bin/g++
1 Well, mostly, anyways. Usual prefixes include /
(binaries in /bin/
), /usr/
(binaries in /usr/bin/
) and /usr/local/
(binaries in /usr/local/bin/
)
2 I am assuming you want to keep GCC installed at that awkward location. Recompiling and re-installing with --prefix=/opt/gcc-8.1
or something similar would probably be better, just modify the path as needed
Answered By - hlt Answer Checked By - Marilyn (WPSolving Volunteer)