嗨,我在 gcc 和 g++ 上遇到了更新替代方案的问题。从下面的更新替代方案的输出中可以看出,我选择了 gcc 4.8,但当我通过 --version 检查时,它仍然显示 gcc 6.5。我已经检查过类似的帖子,例如这和这。我检查了我的 ~/.bashrc 和 ~/.profile,但没有这个 gcc 的路径。请帮忙解决这个问题,谢谢
以下是 which gcc 的输出:
/usr/local/cuda-9.0/bin/gcc
以下是 echo $PATH 的输出:
/home/cgal/anaconda3/bin:/home/cgal/anaconda3/condabin:/usr/local/cuda-9.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
以下是更新替代方案的输出:
There are 3 choices for the alternative gcc (providing /usr/bin/gcc).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/gcc-4.8 3 auto mode
* 1 /usr/bin/gcc-4.8 3 manual mode
2 /usr/bin/gcc-6 1 manual mode
3 /usr/bin/gcc-7 2 manual mode
Press <enter> to keep the current choice[*], or type selection number:
以下是 ./bashrc 条目的输出:
export PATH=/usr/local/cuda-9.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:$LD_LIBRARY_PATH
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/cgal/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/home/cgal/anaconda3/etc/profile.d/conda.sh" ]; then
. "/home/cgal/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/home/cgal/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
export PYTHONPATH=/home/cgal/caffe/python:$PYTHONPATH
以下是 ~/.profile 的输出:
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
以下是 /etc/profile 的输出:
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
if [ "${PS1-}" ]; then
if [ "${BASH-}" ] && [ "$BASH" != "/bin/sh" ]; then
# The file bash.bashrc already sets the default PS1.
# PS1='\h:\w\$ '
if [ -f /etc/bash.bashrc ]; then
. /etc/bash.bashrc
fi
else
if [ "`id -u`" -eq 0 ]; then
PS1='# '
else
PS1='$ '
fi
fi
fi
if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
unset i
fi
最后,问题是:
gcc --version
gcc (Ubuntu 6.5.0-2ubuntu1~18.04) 6.5.0 20181026
Copyright (C) 2017 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.
答案1
在您的 PATH 中,您/home/cgal/anaconda3/bin:/home/cgal/anaconda3/condabin:/usr/local/cuda-9.0/bin
之前有系统正常路径(/usr/...),因此系统会在 /usr/local/cuda-9.0/bin/gcc 中找到 gcc。
将 PATH 开头的三个条目移到结尾。然后您将找到通过更新替代方案设置的 gcc。
在 .bashrc 中有以下行:
export PATH=/usr/local/cuda-9.0/bin:$PATH
将其更改为
export PATH=$PATH:/usr/local/cuda-9.0/bin
以避免在 /usr/local/cuda-9.0/bin/ 中找到 gcc。请记住通过运行. .bashrc
或关闭终端并打开一个新终端来重新加载 .bashrc。