看了网上很多文章 gcc安装很轻松,但是g++的安装过程就曲折多了。写此博客记录一下Debian9.5操作系统下g++安装过程。
首先替换apt源为阿里云的源:
debian 配置
debian 7.x (wheezy)
编辑/etc/apt/sources.list文件(需要使用sudo), 在文件最前面添加以下条目(操作前请做好相应备份)
deb http://mirrors.aliyun.com/debian/ wheezy main non-free contrib
deb http://mirrors.aliyun.com/debian/ wheezy-proposed-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ wheezy main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ wheezy-proposed-updates main non-free contrib
debian 8.x (jessie)
编辑/etc/apt/sources.list文件(需要使用sudo), 在文件最前面添加以下条目(操作前请做好相应备份)
deb http://mirrors.aliyun.com/debian/ jessie main non-free contrib
deb http://mirrors.aliyun.com/debian/ jessie-proposed-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ jessie main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ jessie-proposed-updates main non-free contrib
debian 9.x (stretch)
编辑/etc/apt/sources.list文件(需要使用sudo), 在文件最前面添加以下条目(操作前请做好相应备份)
deb http://mirrors.aliyun.com/debian/ stretch main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ stretch main non-free contrib
deb http://mirrors.aliyun.com/debian-security stretch/updates main
deb-src http://mirrors.aliyun.com/debian-security stretch/updates main
deb http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib
deb http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib
#apt-get update && apt-get upgrade
安装gcc
sudo apt-get install gcc
安装g++
sudo apt-get install g++
报错:
The following packages have unmet dependencies:
dhcp3-server : Depends: g++-5(XXX) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
网上查阅资料使用:
sudo apt-get install build-essential
还是几乎相同的错误,依赖关系的问题。
解决方法
首先安装aptitude
sudo apt-get install aptitude
aptitude简介:
aptitude
(Debian系统的包管理工具)
aptitude与 apt-get 一样,是 Debian 及其衍生系统中功能极其强大的包管理工具。与 apt-get 不同的是,aptitude在处理依赖问题上更佳一些。举例来说,aptitude在删除一个包时,会同时删除本身所依赖的包。这样,系统中不会残留无用的包,整个系统更为干净。
(摘自百度百科)
使用命令:
aptitude install build-essential m4
注意:这个m4很关键,网上很多资料没有这个m4,没有这个m4是无法成功安装g++的。
最后 g++ --version 验证成功安装。