3

In my Ubuntu 18.04 LTS:

marco@PC:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.1 LTS
Release:        18.04
Codename:       bionic

I have gcc version 7.3.0:

marco@PC:~$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu    
7.3.0-21ubuntu1~16.04' --with-bugurl=file:///usr/share/doc/gcc-
7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++
--prefix=/usr --with-gcc-major-version-only --program-suffix=-7 
--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 --with-sysroot=/ --enable-
clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-
default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-
verify --enable-libmpx --enable-plugin --with-system-zlib --with-target-
system-zlib --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 
--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 7.3.0 (Ubuntu 7.3.0-21ubuntu1~16.04)

And I want to install gcc-8:

marco@PC:~$ sudo apt-get install gcc-8
[sudo] password for marco:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 gcc-8 : Depends: cpp-8 (= 8.1.0-1ubuntu1) but it is not going to be   
installed
         Depends: gcc-8-base (= 8.1.0-1ubuntu1) but 8.1.0-5ubuntu1~16.04 
is to be installed
         Depends: libgcc-8-dev (= 8.1.0-1ubuntu1) but it is not going to 
be installed
E: Unable to correct problems, you have held broken packages.

Following the hints found here askUbuntu:Unable to correct problems, you have held broken packages

marco@PC:~$ sudo apt-get update
[sudo] password for marco:
Hit:1 http://security.ubuntu.com/ubuntu bionic-security InRelease
Hit:2 http://cz.archive.ubuntu.com/ubuntu bionic InRelease
Hit:3 http://us.archive.ubuntu.com/ubuntu bionic InRelease
Get:4 http://us.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Hit:5 http://us.archive.ubuntu.com/ubuntu bionic-backports InRelease
Fetched 88.7 kB in 1s (107 kB/s)
Reading package lists... Done
marco@PC:~$ sudo apt-get autoremove
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
marco@PC:~$ dpkg --get-selections | grep hold
marco@PC:~$ sudo apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
marco@PC:~$ sudo apt-get update
Hit:1 http://security.ubuntu.com/ubuntu bionic-security InRelease
Hit:2 http://cz.archive.ubuntu.com/ubuntu bionic InRelease
Hit:3 http://us.archive.ubuntu.com/ubuntu bionic InRelease
Get:4 http://us.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Hit:5 http://us.archive.ubuntu.com/ubuntu bionic-backports InRelease
Fetched 88.7 kB in 1s (123 kB/s)
Reading package lists... Done

Then, I checked the PPA repository used, as suggested:

marco@PC:~$ apt-cache policy gcc-8 cpp-8 libgcc-8-dev
gcc-8:
  Installed: (none)
  Candidate: 8.1.0-1ubuntu1
  Version table:
     8.1.0-1ubuntu1 500
        500 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu    
bionic/main amd64 Packages
     8-20180414-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu bionic/universe amd64  
Packages
cpp-8:
  Installed: (none)
  Candidate: 8.1.0-1ubuntu1
  Version table:
     8.1.0-1ubuntu1 500
        500 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu  
bionic/main amd64 Packages
     8-20180414-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu bionic/universe amd64   
Packages
libgcc-8-dev:
  Installed: (none)
  Candidate: 8.1.0-1ubuntu1
  Version table:
     8.1.0-1ubuntu1 500
        500 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu 
bionic/main amd64 Packages
     8-20180414-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu bionic/universe amd64      
        Packages

I then removed the PPA ubuntu-toolchain-r/test :

sudo add-apt-repository --remove ppa:ubuntu-toolchain-r/test
 Toolchain test builds; see https://wiki.ubuntu.com/ToolChain
 More info: https://launchpad.net/~ubuntu-toolchain-r/+archive/ubuntu/test
Press [ENTER] to continue or Ctrl-c to cancel removing it.

But the problem remains:

marco@PC:~$ sudo apt-get install gcc-8
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 gcc-8 : Depends: cpp-8 (= 8-20180414-1ubuntu2) but it is not going to be 
installed
         Depends: gcc-8-base (= 8-20180414-1ubuntu2) but 8.1.0-5ubuntu1~16.04  
is to be installed
         Depends: libgcc-8-dev (= 8-20180414-1ubuntu2) but it is not going to 
be installed
E: Unable to correct problems, you have held broken packages.

marco@PC:~$ sudo apt-get install cpp-8
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 cpp-8 : Depends: gcc-8-base (= 8.1.0-1ubuntu1) but 8.1.0-5ubuntu1~16.04 
 is to be installed
E: Unable to correct problems, you have held broken packages.

marco@PC:~$ sudo apt-get install gcc-8-base
Reading package lists... Done
Building dependency tree
Reading state information... Done
gcc-8-base is already the newest version (8.1.0-5ubuntu1~16.04).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

marco@PC:~$ sudo apt-get install libgcc-8-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libgcc-8-dev : Depends: gcc-8-base (= 8.1.0-1ubuntu1) but   
8.1.0-5ubuntu1~16.04 is to be installed
                Depends: libasan5 (>= 8.1.0-1ubuntu1) but it is not going
 to be installed
                Depends: libubsan1 (>= 8.1.0-1ubuntu1) but it is not 
 going to be installed
E: Unable to correct problems, you have held broken packages.

marco@PC:~$ sudo apt-get install libasan5
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libasan5 : Depends: gcc-8-base (= 8.1.0-1ubuntu1) but   
 8.1.0-5ubuntu1~16.04 is to be installed
E: Unable to correct problems, you have held broken packages.

marco@PC:~$ sudo apt-get install libubsan1
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libubsan1 : Depends: gcc-8-base (= 8.1.0-1ubuntu1) but     
 8.1.0-5ubuntu1~16.04 is to be installed
E: Unable to correct problems, you have held broken packages.

So... it seems that in order to install gcc-8 I have to install other packages which depend on other packages, which depend themself on gcc-8-base, which is already correctly installed.

And it says "broken packages"... so how to solve the problem? Looking forward to your kind hints and help. Marco

Updating:

marco@PC:~$ sudo apt-get install ppa-purge
Reading package lists... Done
Building dependency tree
Reading state information... Done
ppa-purge is already the newest version (0.2.8+bzr63).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

marco@PC:~$ sudo ppa-purge ppa:ubuntu-toolchain-r/test
Updating packages lists
PPA to be removed: ubuntu-toolchain-r test
Warning:  Could not find package list for PPA: ubuntu-toolchain-r test

marco@PC:~$ sudo apt-get update
Hit:1 http://cz.archive.ubuntu.com/ubuntu bionic InRelease
Hit:2 http://us.archive.ubuntu.com/ubuntu bionic InRelease
Hit:3 http://security.ubuntu.com/ubuntu bionic-security InRelease
Hit:4 http://us.archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:5 http://us.archive.ubuntu.com/ubuntu bionic-backports InRelease
Reading package lists... Done

marco@PC:~$ sudo apt install gcc-8-base gcc-8 cpp-8 libgcc-8-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
gcc-8-base is already the newest version (8.1.0-5ubuntu1~16.04).
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 cpp-8 : Depends: gcc-8-base (= 8-20180414-1ubuntu2) but 8.1.0-5ubuntu1~16.04  
 is to be installed
 gcc-8 : Depends: gcc-8-base (= 8-20180414-1ubuntu2) but 8.1.0-5ubuntu1~16.04
 is to be installed
 libgcc-8-dev : Depends: gcc-8-base (= 8-20180414-1ubuntu2) but    
 8.1.0-5ubuntu1~16.04 is to be installed
                 Depends: libasan5 (>= 8-20180414-1ubuntu2) but it is not
                  going to be installed
                 Depends: libubsan1 (>= 8-20180414-1ubuntu2) but it is not 
                  going to be installed
 E: Unable to correct problems, you have held broken packages.

After installing aptitude I followed the suggestions indicated by aptitude. Now I have this situation:

marco@PC:~$ sudo update-alternatives --config gcc
There are 2 choices for the alternative gcc (providing /usr/bin/gcc).

  Selection    Path            Priority   Status
------------------------------------------------------------
* 0            /usr/bin/gcc-7   700       auto mode
  1            /usr/bin/gcc-7   700       manual mode
  2            /usr/bin/gcc-8   80        manual mode


 marco@PC:~$ g++ -std=c++17 HelloWorld.cpp -oHelloWorld
marco@PC:~$ ./HelloWorld
Hello World!

If I choose to use gcc-8 :

marco@PC:~$ sudo update-alternatives --config gcc
There are 2 choices for the alternative gcc (providing /usr/bin/gcc).

  Selection    Path            Priority   Status
------------------------------------------------------------
* 0            /usr/bin/gcc-7   700       auto mode
  1            /usr/bin/gcc-7   700       manual mode
  2            /usr/bin/gcc-8   80        manual mode

Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/bin/gcc-8 to provide /usr/bin/gcc (gcc) in 
manual mode
update-alternatives: warning: skip creation of /usr/bin/g++ because 
associated file /usr/bin/g++-8 (of link group gcc) doesn't exist


marco@PC:~$ sudo aptitude install g++-8
The following NEW packages will be installed:
  g++-8 libstdc++-8-dev{a}
0 packages upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 9,623 kB of archives. After unpacking 43.7 MB will be used.
Do you want to continue? [Y/n/?] Y
Get: 1 http://us.archive.ubuntu.com/ubuntu bionic/universe amd64 libstdc++-8-
dev amd64 8-20180414-1ubuntu2 [1,536 kB]
Get: 2 http://us.archive.ubuntu.com/ubuntu bionic/universe amd64 g++-8 amd64 
8-20180414-1ubuntu2 [8,088 kB]
Fetched 9,623 kB in 1s (7,165 kB/s)
Selecting previously unselected package libstdc++-8-dev:amd64.
(Reading database ... 92421 files and directories currently installed.)
Preparing to unpack .../libstdc++-8-dev_8-20180414-1ubuntu2_amd64.deb ...
Unpacking libstdc++-8-dev:amd64 (8-20180414-1ubuntu2) ...
Selecting previously unselected package g++-8.
Preparing to unpack .../g++-8_8-20180414-1ubuntu2_amd64.deb ...
Unpacking g++-8 (8-20180414-1ubuntu2) ...
Setting up libstdc++-8-dev:amd64 (8-20180414-1ubuntu2) ...
Setting up g++-8 (8-20180414-1ubuntu2) ...
Processing triggers for man-db (2.8.3-2) ...


marco@PC:~$ sudo update-alternatives --config gcc
There are 2 choices for the alternative gcc (providing /usr/bin/gcc).

  Selection    Path            Priority   Status
------------------------------------------------------------
  0            /usr/bin/gcc-7   700       auto mode
  1            /usr/bin/gcc-7   700       manual mode
* 2            /usr/bin/gcc-8   80        manual mode

Press <enter> to keep the current choice[*], or type selection number:
update-alternatives: warning: forcing reinstallation of alternative /usr/bin
/gcc-8 because link group gcc is broken

Now, after rebooting, it seems working:

marco@PC:~$ sudo update-alternatives --config gcc
There are 2 choices for the alternative gcc (providing /usr/bin/gcc).

      Selection    Path            Priority   Status
------------------------------------------------------------
  0            /usr/bin/gcc-7   700       auto mode
  1            /usr/bin/gcc-7   700       manual mode
* 2            /usr/bin/gcc-8   80        manual mode

Press <enter> to keep the current choice[*], or type selection number:
marco@PC:~$ g++ -std=c++17 HelloWorld.cpp -oHelloWorld
marco@PC:~$ ./HelloWorld
Hello World!

marco@PC:~$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu   
8-20180414-1ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs  
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr   
--with-gcc-major-version-only --with-as=/usr/bin/x86_64-linux-gnu-as --with- 
ld=/usr/bin/x86_64-linux-gnu-ld --program-suffix=-8 --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 --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-
libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-
object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-
default-pie --with-system-zlib --with-target-system-zlib --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 --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 8.0.1 20180414 (experimental) [trunk revision 259383] (Ubuntu 
8-20180414-1ubuntu2)
user2315094
  • 247
  • 2
  • 6
  • 17
  • 1
    It seems that you have added PPA to your system. Version numbers differ from official ones (compare 8.1.0-1ubuntu1 and 8-20180414-1ubuntu2). Please add output of apt-cache policy gcc-8 cpp-8 libgcc-8-dev to the question. – N0rbert Sep 02 '18 at 09:41
  • Do you mind if I do it in few hours? I'm out of reach to my PC right now. By the way, I thank you very much for you very kind prompt reply to my question – user2315094 Sep 02 '18 at 09:45
  • No problem, you got the idea :) – N0rbert Sep 02 '18 at 09:47
  • @N0rbert I added the output of apt-cache policy gcc-8 cpp-8 libgcc-8-dev – user2315094 Sep 03 '18 at 06:05
  • @karel I followed the hints suggested here https://askubuntu.com/questions/223237/unable-to-correct-problems-you-have-held-broken-packages but the problem remains – user2315094 Sep 03 '18 at 07:38

1 Answers1

4

Incompatible repository(s) from 16.04 from in your software sources are interfering with installing other packages in Ubuntu 18.04 and causing an error message about broken packages, so remove those incompatible repositories with ppa-purge from your software sources.

Then you will be able to install the packages that you need from the default Ubuntu 18.04 repositories. Open the terminal and type:

sudo apt-get install ppa-purge
sudo apt update 
sudo apt install aptitude 
sudo aptitude install libubsan1 libasan5 libgcc-8-dev gcc-8-base gcc-8 cpp-8 g++-8 

Follow the suggestions of aptitude if there is a dependency issue after running the last command, because aptitude is a little bit smart about suggesting how to resolve dependency issues that are caused by broken packages.

karel
  • 114,770
  • as I did before and described on my updated problem description, I followed these steps and the problem remains : marco@PC:~$ sudo add-apt-repository --remove ppa:ubuntu-toolchain-r/test marco@PC:~$ sudo apt update marco@PC:~$ sudo apt install gcc-8 cpp-8 libgcc-8-dev Reading package lists... Done Building dependency tree Reading state information Done Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. – user2315094 Sep 03 '18 at 08:09
  • The following information may help to resolve the situation:

    The following packages have unmet dependencies: cpp-8 : Depends: gcc-8-base (= 8-20180414-1ubuntu2) but 8.1.0-5ubuntu1~16.04 is to be installed gcc-8 : Depends: gcc-8-base (= 8-20180414-1ubuntu2) but 8.1.0-5ubuntu1~16.04 is to be installed

    – user2315094 Sep 03 '18 at 08:12
  • marco@PC:~$ sudo apt-get install ppa-purge marco@PC:~$ sudo ppa-purge ppa:ubuntu-toolchain-r/test marco@PC:~$ sudo apt update marco@PC:~$ sudo apt-get upgrade marco@PC:~$ sudo apt-get update marco@PC:~$ sudo apt install gcc-8-base gcc-8 cpp-8 libgcc-8-dev The following packages have unmet dependencies: cpp-8 : Depends: gcc-8-base gcc-8 : Depends: gcc-8-base libgcc-8-dev : Depends: gcc-8-base Depends: libasan5 Depends: libubsan1 E: Unable to correct problems, you have held broken packages. – user2315094 Sep 03 '18 at 09:37
  • Thank you very much @karel and N0rbert . Now it seems working as described above – user2315094 Sep 03 '18 at 10:55
  • Anyone have a solution that doesn't require aptitude? – Cameron Tacklind Mar 29 '20 at 11:57
  • @CameronTacklind This solution uses Synaptic package manager (GUI app) instead of aptitude terminal program: https://askubuntu.com/a/1081938. – karel Mar 29 '20 at 12:00