web-dev-qa-db-ja.com

Ubuntu 18.04.01 LTSでgcc7.3をgcc8に正しくアップグレードする方法

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

gccバージョン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)

そして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.

ここにあるヒントに従ってください askUbuntu:問題を修正できません、壊れたパッケージを持っています

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

次に、提案されているように、使用したPPAリポジトリを確認しました。

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

次に、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.

しかし、問題は残ります。

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.

だから... gcc-8をインストールするためには、すでに正しくインストールされているgcc-8-baseに依存する他のパッケージに依存する他のパッケージをインストールする必要があるようです。

そして、それは「壊れたパッケージ」と言います...問題を解決する方法は?あなたの親切なヒントと助けを楽しみにしています。マルコ

更新中:

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.

Aptitudeをインストールした後、aptitudeが示す提案に従いました。今、私はこの状況を持っています:

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!

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

今、再起動後、動作しているようです:

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)
3
user2315094

ソフトウェアソース内の16.04からの互換性のないリポジトリは、Ubuntu 18.04の他のパッケージのインストールを妨げ、破損したパッケージに関するエラーメッセージが表示されるため、ソフトウェアソースからppa-purgeで互換性のないリポジトリを削除します。

その後、デフォルトのUbuntu 18.04リポジトリから必要なパッケージをインストールできます。ターミナルを開き、次を入力します。

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 

最後のコマンドの実行後に依存関係の問題がある場合は、aptitudeの提案に従います。aptitudeは、破損したパッケージが原因の依存関係の問題を解決する方法を提案するのが少し賢いためです。

3
karel