0

Hi I have encountered problem regarding update alternative on gcc and g++. As can be seen on the output of update alternative below, I have chosen gcc 4.8 but when I check via --version it still says gcc 6.5. I have already check similar post like this and this. I checked my ~/.bashrc and ~/.profile but there are no path to this gcc. Please help resolve this thank you

Here is the output of which gcc :

/usr/local/cuda-9.0/bin/gcc

Here is the output of 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

Here is the output of update alternatives:

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:

Here is the output from ./bashrc entries:

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

Here is output from ~/.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

Here is output from /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

Lastly this is the problem :

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.
2
  • Please edit your question and add the output of which gcc and echo $PATH. And please don't post screenshots of the terminal if possible. Instead, copy the relevant text and include it in your question as a code block (the { } button on top of the text editor). – danzel Aug 30 '19 at 9:19
  • Hi, thank you for the reply. I have fixed my post. I hope you can help me with it – Wanttobepro Aug 30 '19 at 10:19
2

In your PATH you have /home/cgal/anaconda3/bin:/home/cgal/anaconda3/condabin:/usr/local/cuda-9.0/bin before the systems normal paths (/usr/...) so the system finds gcc in /usr/local/cuda-9.0/bin/gcc.

Move the three entries from the beginning of PATH to the end instead. Then you will find the gcc you have set by update alternatives.

In .bashrc you have this line:

export PATH=/usr/local/cuda-9.0/bin:$PATH

change that to

export PATH=$PATH:/usr/local/cuda-9.0/bin

to avoid finding the gcc in /usr/local/cuda-9.0/bin/. Remember to reload .bashrc by running . .bashrc or close terminal and open a new one.

4
  • Hi thank you for the reply. Would you be able to guide me on how to do it? I checked on other post that I need to edit the ~/.bashrc to do it but the order somehow doesn't follow the echo result and I cant find the normal path inside so I don't know where I should put the other 3 entries because those 3 already on the end of bashrc. Thank you (if you want I can put the output of bashrc on the post, only the 3 entries part) – Wanttobepro Aug 30 '19 at 10:41
  • Yes, please update the question with that info. Also check .profile and /etc/profile for PATH modification, and put that in the question too, if there are any. – Soren A Aug 30 '19 at 10:45
  • I already put all on the post. I have never open /etc/profile before, I hope it is correct – Wanttobepro Aug 30 '19 at 10:56
  • I have updated the answer with what to change. – Soren A Aug 30 '19 at 12:35

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.