我安裝了相對較新的 RHEL 6.5,並從原始碼 GCCC 4.9 安裝到了該版本。安裝 GCC 4.9 後,我透過以下方式卸載了發行版提供的舊 GCC 版本:
sudo yum remove gcc
海灣合作委員會出現正確安裝並對使用者和使用者可見root
,但是當我嘗試發出sudo
需要編譯器的命令時,找不到它。
在我看來,這PATH
並不指向g++
while sudo
,但我不明白為什麼。
g++
安裝在:
[john@haley boost_1_55_0]$ which g++
/usr/local/bin/g++
並以使用者身分取得版本並root
成功:
[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.
但sudo g++ --version
失敗了:
john@haley boost_1_55_0]$ sudo g++ --version
[sudo] password for john:
sudo: g++: command not found
[john@haley boost_1_55_0]$
檢查PATH
為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
^^^^^^^^^
....似乎表明 的位置g++
實際上在路徑中。
為什麼會失敗,我能做些什麼來解決這個問題?
回答評論中的問題:
是的,我可以使用以下顯式路徑執行它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]$
據觀察,我在檢查時做錯了sudo PATH
。以正確的方式去做表示/usr/local/bin
事實上不是在sudo
的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]$
答案1
我將其發佈為答案,因為我透過對OP的評論發現了這個解決方案,但我不確定這就是我想要的應該做。
我可以透過運行sudo visudo
和編輯來完成這項工作secure_path
以包含/usr/local/bin
.
在我的系統上,原始行是:
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin
將其更改為:
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
「修復」問題:
[john@haley boost_1_55_0]$ sudo 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]$