How to update gcc linux

Update GCC on Ubuntu

I am on a project that needs GCC 10.x or later. At this time I have GCC 9.4.0 on Ubuntu 20.04.1. I tried to update the compiler, but it does not work. Can anybody give me an advice for the update? I read on the gcc website that version 9.4 is more up-to-date than some 10.x versions. How is Gcc structured? among other things I tried:

sudo apt-get install gcc-10.2 g++-10.2 
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0 

GCC 10 will be named gcc-10 (or something similar, not gcc ). «version 9.4 is more up-to-date than some 10.x versions» They mean 9.y can be released after 10.x to fix some bugs in the old version, but it doesn’t really matter. Bigger number = better version.

You could also upgrade to Ubuntu 22.04 which is the latest LTS version and it comes with gcc 11.3. I did that on my Ubuntu WSL installation and it was a painless upgrade.

1 Answer 1

This is a common pattern in linux. When there are multiple versions of the same program installed, though the executables are all present in the /usr/bin/ directory, only one of them is «visible» as that program. For example, if you install gcc-9 and gcc-10 , both executables are present as /usr/bin/gcc-9 and /usr/bin/gcc-10 but only one of them is visible as gcc . This happens by symlinking a preferred version to the same directory as /usr/bin/gcc . In ubuntu 20.04, the preferred version is gcc-9 and so, gcc-9 is symlinked as gcc .

You can check this by running the following command.

/usr/bin/gcc: symbolic link to gcc-9 

There are a few things you can do to use gcc-10 as your c compiler.

  1. Directly call the gcc-10 executable. Instead of using gcc , call gcc-10 .
  2. You can manually symlink gcc-10 as the preferred gcc . Assuming you did not modify the system paths, the following command can be used.
# ln -s /usr/bin/gcc-10 /usr/local/bin/gcc 

This works because, by default, the executables in /usr/local/bin/ take precedence over /usr/bin/ .

  1. If you are using bash, you can create an alias for gcc as gcc-10 . Add the following line to your .bashrc .

Remember to relaunch bash or source ~/.bashrc .

  1. Using update-alternatives (Thanks to @ted-lyngmo for pointing it out). Debian based distributions supply a separate program, that can make symlinking easier / more functional. Read more using man update-alternatives . To use gcc-10 as the preferred gcc , use the following command.
# update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 60 

The above command says, /usr/bin/gcc is the link needed and the name is gcc , the target executable is /usr/bin/gcc-10 and it has a priority of 60.

Читайте также:  Enable ssh on linux mint

This links gcc to /etc/alternatives/gcc , which itself is a symlink to /usr/bin/gcc-10 . If a higher priority program is added to update-alternatives , /etc/alternatives/gcc points to the higher priority program.

If you don’t have any specific reason, I would also recommend to upgrade to a newer ubuntu version, so that the default gcc is a newer one.

I read on the gcc website that version 9.4 is more up-to-date than some 10.x versions.

With newer gcc versions, new features are added. Support for newer c/c++ standards are also added. Eg. You can read the changes for gcc-10 here. But people still need gcc-9 because some programs only build with gcc-9 . So, GNU maintains gcc-9 (and much older versions) for a long time. Bugs are fixed, and newer releases are made. This can happen after the release of a newer gcc version. So, it is very much possible that a version of gcc-9 is newer than a version of gcc-10 .

Источник

gcc update ubuntu

Better C++ 11 support is on the latest gcc version. You might to compile it yourself though Note that gcc 4.7 is almost ready for release, so, you might want to give it a try. . In general, it is a good idea to use the latest g++ compiler. However, in a few occasions I have had problems with the libraries that I use.

Where is gcc installed on Ubuntu?

You need to use the which command to locate c compiler binary called gcc. Usually, it is installed in /usr/bin directory.

How do I check my GCC version?

  1. Question : How to check gcc version on my Ubuntu ?
  2. Answer : gcc – GNU project C and C++ compiler. There are a few options to obtain GCC version in Ubuntu.
  3. Option 1. Issue command “gcc –version” Example : .
  4. Option 2. Issue command “gcc -v” .
  5. Option 3. Issue command “aptitude show gcc”

How do I get rid of GCC?

—purge Use purge instead of remove for anything that would be removed. An asterisk («*») will be displayed next to packages which are scheduled to be purged. remove —purge is equivalent to the purge command. Configuration Item: APT::Get::Purge.

Is clang better than GCC?

Clang is much faster and uses far less memory than GCC. Clang aims to provide extremely clear and concise diagnostics (error and warning messages), and includes support for expressive diagnostics. GCC’s warnings are sometimes acceptable, but are often confusing and it does not support expressive diagnostics.

Is GCC written in C or C++?

The GNU Compiler Collection (GCC) was, from its inception, written in C and compiled by a C compiler. Beginning in 2008, an effort was undertaken to change GCC so that it could be compiled by a C++ compiler and take advantage of a subset of C++ constructs.

Is GCC a C++ compiler?

GCC, formerly for «GNU C Compiler», has grown over times to support many languages such as C ( gcc ), C++ ( g++ ), Objective-C, Objective-C++, Java ( gcj ), Fortran ( gfortran ), Ada ( gnat ), Go ( gccgo ), OpenMP, Cilk Plus, and OpenAcc. It is now referred to as «GNU Compiler Collection».

Читайте также:  1c enterprise client linux

What version of GCC should I use?

The kernel build requirements are quite conservative: for kernel 4.18, GCC 3.2 and binutils 2.20 are sufficient. Thus your distribution’s compiler should work fine. In practice pretty much any version of GCC will do, although one can sometimes run into problems with versions of GCC which are too new.

How do I install multiple gcc versions?

  1. installing GCC-7 GCC-8. .
  2. install GCC -9 repository. .
  3. Install GCC-9 on Ubuntu 20.04. .
  4. Install G++ Compilers. .
  5. Create a List of GCC and G++ alternatives. .
  6. Set your default GCC compiler. .
  7. Select the Default G++ Compiler. .
  8. Run the G++ and GCC version command.

What is a GCC?

Alternative Titles: GCC, Gulf States. Gulf Cooperation Council (GCC), political and economic alliance of six Middle Eastern countries—Saudi Arabia, Kuwait, the United Arab Emirates, Qatar, Bahrain, and Oman.

Change Swap Size in Ubuntu

Swap

How do I change swap size in Ubuntu?How do I change the swap file size?How do I change the swap size in Linux?How do I fix swap space in Linux?How do .

The Complete Guide for Using ffmpeg in Linux

Ffmpeg

How do I run FFmpeg in Linux?How do I use FFmpeg command?How do I configure FFmpeg?Where is Ffmpeg path in Linux?Does Ffmpeg work on Linux?What is FFm.

How to Restart Networking on Ubuntu

Restart

Ubuntu / DebianUse the following command to restart the server networking service. # sudo /etc/init.d/networking restart or # sudo /etc/init.d/network.

Latest news, practical advice, detailed reviews and guides. We have everything about the Linux operating system

Источник

How to use a newer version of gcc on ubuntu?

How is it that I do not have alternative for gcc ? Any suggestions on how I can resolve this error and configure gcc-8 to be the default gcc installation would be appreciated. Running which gcc from outside the conda environment does not return anything:

ubuntu@user:~$ which gcc ubuntu@user:~$ 
ubuntu@user:~$ gcc-8 --version gcc-8 (Ubuntu 8.3.0-6ubuntu1~18.04.1) 8.3.0 
(tensorflow_p36) ubuntu@user:~$ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 40 (tensorflow_p36) ubuntu@user:~$ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 60 (tensorflow_p36) ubuntu@user:~$ sudo update-alternatives --config g++ There are 3 choices for the alternative g++ (providing /usr/bin/g++). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/bin/x86_64-linux-gnu-g++-7 100 auto mode 1 /usr/bin/g++-4.8 60 manual mode 2 /usr/bin/g++-8 40 manual mode 3 /usr/bin/x86_64-linux-gnu-g++-7 100 manual mode Press to keep the current choice[*], or type selection number: 2 update-alternatives: using /usr/bin/g++-8 to provide /usr/bin/g++ (g++) in manual mode 

You need to set a specific gcc executable as an alternative to gcc and a specific g++ executable as an alternative to g++, never mix them and do not use —slave . Use two separate update-alternatives commands, one for gcc and one for g++.

You are using the gcc provided by anaconda, not the one installed from the ubuntu repositories. As you are saying the problem is not presents outside the conda environment. So I guess you should be asking how to upgrade to a newer gcc version in anaconda.

1 Answer 1

It’s possible you arrived because something blew up with nvidia. (I’m on cudatoolkit 11.4 and actually downgrading got me out of trouble — your mileage may vary.)

sudo apt install gcc-9 g++-9 sudo mkdir /usr/local/cuda/bin sudo ln -s /usr/bin/gcc-9 /usr/local/cuda/bin/gcc 

WARNING — I recommend using timeshift to make a backup of your working system. https://github.com/teejee2008/timeshift

Читайте также:  Узнать свой ip линукс через терминал

This will get you the latest gcc 11

sudo add-apt-repository 'deb http://mirrors.kernel.org/ubuntu hirsute main universe' sudo apt-get install g++-11 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 50 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 50 sudo update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-11 100 sudo update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-11 50 sudo update-alternatives --set g++ /usr/bin/g++-11 sudo update-alternatives --set gcc /usr/bin/gcc-11 sudo update-alternatives --set cpp-bin /usr/bin/cpp-11 gcc --version gcc (Ubuntu 11-20210417-1ubuntu1) 11.0.1 20210417 

Copyright (C) 2021 Free Software Foundation, Inc.

Источник

How do I use the latest GCC on Ubuntu?

I want to compile my program with the latest version of gcc . Ubuntu 14.04 comes with gcc 4.8.2, however there’s 4.9.0 available, moreover, I see that it is available as a package: gcc-4.9 . I tried to install it

sudo apt-get install gcc-4.9 
Reading package lists. Done Building dependency tree Reading state information. Done Note, selecting 'gcc-4.9-base' for regex 'gcc-4.9' gcc-4.9-base is already the newest version. 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 

Looks like it is already installed, just not as the default one? How do I utilize it to build my program?

If you want to install gcc-4.8 , you need to use sudo apt-get install gcc-4.8 . gcc-4.9 , gcc-4.8 , gcc-4.7 , gcc-4.6 all are in Ubuntu main repo.

switch to root user : sudo su — goto /usr/bin then run ls -l gcc* and post your output. then I’ll post your answer.

5 Answers 5

The best way to correctly install gcc-4.9 and set it as your default gcc version use:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test sudo apt-get update sudo apt-get install gcc-4.9 g++-4.9 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9 

The —slave , with g++ , will cause g++ to be switched along with gcc , to the same version. But, at this point gcc-4.9 will be your only version configured in update-alternatives , so add 4.8 to update-alternatives , so there actually is an alternative, by using:

sudo apt-get install gcc-4.8 g++-4.8 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8 

Then you can check which one that is set, and change back and forth using:

sudo update-alternatives --config gcc 

If you have an issue with update-alternatives gcc priority 60 not being higher than previous versions installed you can use the previous update-alternatives —config gcc command to check installed versions and use:

sudo update-alternatives --remove gcc 
sudo update-alternatives --remove-all gcc 

NOTE: You could skip installing the PPA Repository and just use /usr/bin/gcc-4.9-base but I prefer using the fresh updated toolchains.

For GCC 5.X or 6, the packages (and correspondingly, the commands) are just called gcc-5 , gcc-6 , etc. This is due to the change in GCC’s version scheme, where 5.1 is the first GCC 5 release, and future 5.X releases are for bug fixes.

Источник

Оцените статью
Adblock
detector