在安装gcc-5 之后接着继续安装对应的g++版本,然后出现如下错误
sudo apt-get install g++-5 E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 12518 (unattended-upgr) N: Be aware that removing the lock file is not a solution and may break your system. E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
解决方法
如上面情况,注意第一行错误的 process 12518 ,正是这个apt进程还在运行,需要将它kill掉,执行如下命令:
sudo kill -9 12518
其中你只需要改的是 12518 这个进程id,看你报的错误是哪个,命令中的9是 SIGKILL 的信号数,它会杀掉第一个 apt 进程,不用管它。
之后就解决了
sudo apt-get install g++-5 Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: linux-headers-5.11.0-37-generic linux-hwe-5.11-headers-5.11.0-37 linux-image-5.11.0-37-generic linux-modules-5.11.0-37-generic linux-modules-extra-5.11.0-37-generic Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: libstdc++-5-dev Suggested packages: g++-5-multilib gcc-5-doc libstdc++6-5-dbg libstdc++-5-doc The following NEW packages will be installed: g++-5 libstdc++-5-dev 0 upgraded, 2 newly installed, 0 to remove and 173 not upgraded. Need to get 9,857 kB of archives. After this operation, 39.0 MB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://mirrors.aliyun.com/ubuntu xenial-updates/main amd64 libstdc++-5-dev amd64 5.4.0-6ubuntu1~16.04.12 [1,428 kB] Get:2 http://mirrors.aliyun.com/ubuntu xenial-updates/main amd64 g++-5 amd64 5.4.0-6ubuntu1~16.04.12 [8,430 kB] Fetched 9,857 kB in 2s (3,976 kB/s) Selecting previously unselected package libstdc++-5-dev:amd64. (Reading database ... 233784 files and directories currently installed.) Preparing to unpack .../libstdc++-5-dev_5.4.0-6ubuntu1~16.04.12_amd64.deb ... Unpacking libstdc++-5-dev:amd64 (5.4.0-6ubuntu1~16.04.12) ... Selecting previously unselected package g++-5. Preparing to unpack .../g++-5_5.4.0-6ubuntu1~16.04.12_amd64.deb ... Unpacking g++-5 (5.4.0-6ubuntu1~16.04.12) ... Setting up libstdc++-5-dev:amd64 (5.4.0-6ubuntu1~16.04.12) ... Setting up g++-5 (5.4.0-6ubuntu1~16.04.12) ... Processing triggers for man-db (2.9.1-1) ...



