new*_*bie 1 versions gcc g++ software-installation
我使用了这里的信息How to install g++ 10 on Ubuntu 18.04? 在 Ubuntu 20 上安装 gcc/g++ 10 ,当我尝试再次执行此操作时:
sudo apt install g++-10
Reading package lists... Done
Building dependency tree
Reading state information... Done
g++-10 is already the newest version (10.2.0-5ubuntu1~20.04).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Run Code Online (Sandbox Code Playgroud)
但是当我询问版本时:
g++ --version
g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 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++-10 --version
g++-10 (Ubuntu 10.2.0-5ubuntu1~20.04) 10.2.0
Copyright (C) 2020 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++10 是以 g++-10 的名称安装和使用的,但如何使其成为默认的 g++ 编译器?
小智 5
您需要使用update-alternatives
来指定默认情况下应使用哪个版本的 g++。就是这样:
update-alternatives
:
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 40
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 60
sudo update-alternatives --config g++
Run Code Online (Sandbox Code Playgroud)
运行最后一个命令后,您将看到一个g++
版本菜单,您可以选择默认g++
版本。该消息将如下所示:
Press <enter> to keep the current choice[*], or type selection number:
Run Code Online (Sandbox Code Playgroud)
从菜单中键入您想要作为默认值的号码,然后按Enter。g++
如果以后需要再次更改默认版本,请再次使用该命令。
注意:如果您还需要更改 gcc 的默认版本,请遵循相同的过程, g++
将 gcc
. 不要忘记更改版本号。
希望这可以帮助