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

URL*_*L87 7 installation 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.
Run Code Online (Sandbox Code Playgroud)

我想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.
Run Code Online (Sandbox Code Playgroud)

如何将我的g++版本更改为与上述相同?

dev*_*av2 5

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

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

然后使用update-alternatives切换版本

sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.3 10
Run Code Online (Sandbox Code Playgroud)

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

sudo update-alternatives --config g++
Run Code Online (Sandbox Code Playgroud)