I have a relatively fresh RHEL 6.5 install, on to which I have installed from source GCCC 4.9. After I installed GCC 4.9, I uninstalled the distro-provided older GCC version via:
sudo yum remove gcc
GCC appears to be correctly installed and visible to both users and root
, but when I try to issue a sudo
command which needs the compiler, it cannot be found.
It seems to me that PATH
doesn't point to g++
during sudo
, but I don't understand why.
g++
is installed in:
[john@haley boost_1_55_0]$ which g++
/usr/local/bin/g++
And getting the version as a user and as root
succeeds:
[john@haley boost_1_55_0]$ g++ --version
g++ (GCC) 4.9.0
Copyright (C) 2014 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.
[john@haley boost_1_55_0]$ sudo su -
root@haley /root # g++ --version
g++ (GCC) 4.9.0
Copyright (C) 2014 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.
But sudo g++ --version
fails:
john@haley boost_1_55_0]$ sudo g++ --version
[sudo] password for john:
sudo: g++: command not found
[john@haley boost_1_55_0]$
Checking the PATH
as sudo
:
[john@haley boost_1_55_0]$ sudo echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/home/john/bin:/usr/local/bin
^^^^^^^^^
... seems to indicate that the location of g++
is actually in the path.
Why is this failing, and what can I do to fix it?
Answering questions in comments:
yes, I can execute it using explicit paths under sudo
:
[john@haley boost_1_55_0]$ sudo /usr/local/bin/g++ --version
[sudo] password for john:
g++ (GCC) 4.9.0
Copyright (C) 2014 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.
[john@haley boost_1_55_0]$
It was observed that I was doing-it-wrong when checking the sudo PATH
. Doing it the right way reveals that in fact /usr/local/bin
is not in sudo
's PATH
:
[john@haley boost_1_55_0]$ sudo env | grep PATH
13:PATH=/sbin:/bin:/usr/sbin:/usr/bin
[john@haley boost_1_55_0]$
sudo
? – psimon Jun 21 '14 at 14:57$PATH
is wrong because$PATH
expanded by the shell. Trysudo env | grep PATH
. – Mikel Jun 21 '14 at 15:02visudo
and add/usr/local/bin
to thesecure_path
? – John Dibling Jun 21 '14 at 15:07