Debian9.5安装g++

本文详细记录了在Debian9.5操作系统中安装g++的过程,包括更换apt源为阿里云源,解决g++安装过程中遇到的依赖问题,最终成功安装并验证。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

看了网上很多文章 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 验证成功安装。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值