How to upgrade gcc-5 to gcc-7 in Ubuntu 16.04?
To answer my own question after much trial and error, it seems not safe to remove/replace the older gcc (gcc-5), because it will break a lot of dependencies to the extent of wiping out the entire tool chain.
For example, when trying to remove/replace gcc-5 as said in the comments with
Run update-alternatives to set gcc-7 as the default gcc version and the type sudo dpkg -r gcc-5
This generates an error:
dpkg: dependency problems prevent removal of gcc-5:
g++-5 depends on gcc-5 (= 5.4.1-2ubuntu1~16.04).
g++ depends on gcc-5 (>= 5.3.1-3~).
gcc depends on gcc-5 (>= 5.3.1-3~).
gfortran-5 depends on gcc-5 (= 5.4.1-2ubuntu1~16.04).
When adding these dependencies to the list of sudo dpkg -r
items, an increasing number of packages need to be removed. e.g.
...
r-base-dev depends on g++.
build-essential depends on g++ (>= 4:5.2).
I haven't tried to find the largest set of packages that will be removed as described in How to uninstall a .deb package? . But it's pretty clear that most of the useful packages in the Ubuntu will be gone by then.
Related videos on Youtube
tinlyx
Updated on September 18, 2022Comments
-
tinlyx over 1 year
This is a follow up question to How to install gcc-7 or clang 4.0?.
Following the answers therein, I was able to install gcc-7.2 by:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test sudo apt-get update sudo apt-get install -y gcc-7
However, after the install, the
gcc
/g++
command still defaults to5.4.0
gcc --version gcc (Ubuntu 5.4.0-6ubuntu1~16.04.5) 5.4.0 20160609
Is it possible/safe to have
gcc-7
as the default and remove the old gcc-5.x files entirely?
Note that, different from the said duplicate, I'm looking to remove/replace gcc-5.x instead of setting a symlink.
-
muru over 6 yearsYou cannot remove
gcc
because it depends ongcc-5
, and packages may break if they depend on gcc.
-