如何安装特定版本的 g++?

如何安装特定版本的 g++?

在我的 Ubuntu 中有g++ --version-

g++ (Ubuntu 4.4.3-4ubuntu5.1) 4.4.3
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

我想g++ --version在另一台 Linux 机器上也安装同样的软件 -

g++ (GCC) 4.1.2 20070626 (Red Hat 4.1.2-14)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

我如何改变我的克++版本和上面的一样吗?

答案1

从以下位置下载 g++-4.1 版本这里。g++-4.1 在最近的 Ubuntu 存储库中不可用。因此您需要从提供的链接下载该软件包。

与当前版本的 g++ 一起安装/编译下载包。

然后使用update-alternatives切换版本

sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.3 10

通过选择适当的版本来更改默认版本:

sudo update-alternatives --config g++

答案2

就我个人而言,我不会恢复到 g++ 的早期版本,除非没有其他可能的方法来实现我想要的结果。g++适用于所有受支持的 Ubuntu 版本存储库并且可以安装sudo apt install g++如果你确实需要多个版本,你需要利用如何选择默认的gcc和g++版本?正如@boomkin 指出的那样这条评论。

相关内容