gcc/g++ 10 está instalado pero no puedo usarlo en Ubuntu 20.04.2 LTS

gcc/g++ 10 está instalado pero no puedo usarlo en Ubuntu 20.04.2 LTS

Usé la información aquí.¿Cómo instalar g++ 10 en Ubuntu 18.04?para instalar gcc/g++ 10 en Ubuntu 20 y cuando intento hacerlo de nuevo:

sudo apt install g++-10

Reading package lists... Done
Building dependency tree       
Reading state information... Done
g++-10 is already the newest version (10.2.0-5ubuntu1~20.04).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

pero cuando pido la versión:

g++ --version

g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 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.

¿A qué se debe esto y cómo puedo solucionarlo?

Actualizar

Sin embargo, cuando lo intento:

g++-10 --version

g++-10 (Ubuntu 10.2.0-5ubuntu1~20.04) 10.2.0
Copyright (C) 2020 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.

Parece que g++10 está instalado y se puede utilizar con el nombre g++-10, pero ¿cómo puedo convertirlo en el compilador predeterminado de g++?

Respuesta1

Deberá usar update-alternativespara especificar qué versión de g++ debe usarse de forma predeterminada. Así es cómo:

  1. Abrir Terminal (si aún no está abierto)
  2. Configurar update-alternatives:
    sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 40
    sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 60
    sudo update-alternatives --config g++
    

Después de ejecutar el último comando, se le presentará un menú de g++versiones y tendrá la opción de elegir su g++versión predeterminada. El mensaje se verá así:

Press <enter> to keep the current choice[*], or type selection number:

Escriba el número del menú que desea tener como predeterminado y luego presione Enter. Si necesita cambiar la versión predeterminada de g++nuevamente en el futuro, use el comando nuevamente.

Nota:Si también necesita cambiar la versión predeterminada de gcc, siga este mismo procedimiento, reemplazando g++ con gcc.No olvide cambiar también los números de versión.

Espero que esto ayude

información relacionada