2

sudo apt-get install gcc-10 g++-10:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
g++-10 is already the newest version (10.3.0-1ubuntu1~20.04).
gcc-10 is already the newest version (10.3.0-1ubuntu1~20.04).
0 upgraded, 0 newly installed, 0 to remove and 31 not upgraded.
<pre>gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion=&apos;Ubuntu 9.4.0-1ubuntu1~20.04&apos; --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-yTrUTS/gcc-9-9.4.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04)</pre>

Im new to linux so if there's anything else you need lmk

1
  • 3
    31 not upgraded. Your system is not up-to-date. Always run sudo apt update before any other command in apt and you should perform updates with sudo apt upgrade before attempting to install new software. Also, when giving us the output of commands, be sure to provide the exact command and the entire output. Don't give us bits and pieces because you can leave out essential diagnostic info.
    – Nmath
    Oct 18, 2021 at 18:10

2 Answers 2

2

Enter the command gcc-10 instead of gcc to use gcc-10.

Alternatively, you can use the command sudo update-alternatives --config gcc to choose gcc-10 as the default gcc. Similarly, use sudo update-alternatives --config g++ to configure the default g++ version.

3
  • 1
    Search this site for "update broke my computer" for some of the consequences of replacing the default gcc version. Change the user's gcc default, via some other mechanism, like an alias, or a gcc link in $HOME/bin to avoid an update failing to recompile a video driver.
    – ubfan1
    Oct 18, 2021 at 18:45
  • @ubfan1 Why would a update use gcc to compile something? Feel free to edit my answer. Oct 19, 2021 at 3:26
  • @ArchismanPanigrahi He is probably using the NVIDIA proprietary driver, which compiles a module during the installation process. Aug 9 at 13:03
0

For any Ubuntu release, the default gcc compiler is selected via a link such as /usr/bin/gcc which links to the actual compiler executable, maybe through other links: /usr/bin/gcc -> gcc-9 -> x86_64-linux-gnu-gcc-9 This is the validated/tested compiler used for the release, and regardless of which compiler version you select for your own use, it is not a good idea to change the system default. Kernel updates may need to rebuild proprietary video modules from vendor supplied binary blobs, and this process is tested with the default compiler. Maybe a later compiler will work, but might not, leaving you booting the latest kernel without the appropriate proprietary video module, causing problems like low resolution (from another video driver) or a even black screen. Multiple compiler versions may be installed, but those installations do not change the /usr/bin/gcc link. You should not manually change that link either, nor should you use update-alternatives to slip a new compiler in.

A user may set up their own environment to run whatever compiler they install via any number of ways. In the case of 20.04 with a default 9.4 compiler and you desire to run a 10 compiler, you may:

  1. Invoke the gcc-10 by name. Use this for managing multiple projects each needing a different compiler. The name may be embedded in project definition files, e.g. in a makefile GCC=gcc-10

  2. Add an alias to your .bashrc file (or equivalent if not running bash). alias gcc="/usr/bin/gcc-10" This way all your projects will get the 10 version of the compiler with the invocation of gcc.

  3. Add a link named gcc in your home directory's bin to the selected compiler version. This assumes your $HOME/bin is earlier in your PATH than /usr/bin or /bin. Again, this will let gcc invoke your selected compiler everywhere.

4)project specific config files may set up aliases or links in project bin directories for controlling what gcc invokes.

Select the mechanism which best suits your needs.

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.