如何更改Ubuntu中的默认GCC编译器?

时间:2022-07-08 07:00:43

I have installed gcc-3.3/g++-3.3 on ubuntu 11.04 which already has gcc/g++-4.4. So in my system both gcc-3.3 and 4.4 are available. I am able to call both compilers as I want. If I just call the command gcc then gcc-4.4 will get called. To call gcc-3.3, I have to use the command gcc-3.3.

我已经在ubuntu 11.04上安装了gcc-3.3/g++-3.3,已经有gcc/g++-4.4。在我的系统中,gcc-3和4.4都是可用的。我可以任意调用两个编译器。如果我只调用命令gcc,那么gcc-4.4就会被调用。要调用gcc-3.3,我必须使用命令gcc-3.3。

How can I change the default compiler as gcc-3.3? When I execute the command gcc it should call the gcc-3.3 and not gcc-4.4.

如何将默认编译器更改为gcc-3.3?当我执行命令gcc时,它应该调用gcc-3.3而不是gcc-4.4。

In addition, how can I change the variable CXX in a make file to gcc-3.3? I wish to change one common global place in the system instead of changing all make files.

另外,如何将make文件中的变量CXX更改为gcc-3.3?我希望更改系统中的一个通用全局位置,而不是更改所有make文件。

8 个解决方案

#1


93  

As @Tommy suggested, you should use update-alternatives.
It assigns values to every software of a family, so that it defines the order in which the applications will be called.

正如@Tommy建议的,您应该使用更新替代。它为一个家族的每个软件分配值,以便定义应用程序调用的顺序。

It is used to maintain different versions of the same software on a system. In your case, you will be able to use several declinations of gcc, and one will be favoured.

它用于在系统上维护同一软件的不同版本。在您的情况下,您将能够使用几个gcc的赤纬,其中一个将会受到青睐。

To figure out the current priorities of gcc, type in the command pointed out by @tripleee's comment:

要确定gcc当前的优先级,输入@tripleee的评论指出的命令:

update-alternatives --query gcc

Now, note the priority attributed to gcc-4.4 because you'll need to give a higher one to gcc-3.3.
To set your alternatives, you should have something like this (assuming your gcc installation is located at /usr/bin/gcc-3.3, and gcc-4.4's priority is less than 50):

现在,请注意gcc-4.4的优先级,因为您需要为gcc-3.3提供更高的优先级。要设置备选方案,您应该具有以下内容(假设您的gcc安装位于/usr/bin/gcc-3.3,并且gcc-4.4的优先级小于50):

update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-3.3 50

--edit--

——编辑

Finally, you can also use the interactive interface of update-alternatives to easily switch between versions. Type update-alternatives --config gcc to be asked to choose the gcc version you want to use among those installed.

最后,您还可以使用update-alternatives的交互式接口来轻松地在版本之间切换。键入update-alternative——要求配置gcc来选择要在安装的gcc版本中使用的gcc版本。

--edit 2 --

——编辑2

Now, to fix the CXX environment variable systemwide, you need to put the line indicated by @DipSwitch's in your .bashrc file (this will apply the change only for your user, which is safer in my opinion):

现在,要在整个系统范围内修复CXX环境变量,您需要将@DipSwitch的行放在.bashrc文件中(这只适用于您的用户,在我看来更安全):

echo 'export CXX=/usr/bin/gcc-3.3' >> ~/.bashrc

#2


64  

Here's a complete example of jHackTheRipper's answer for the TL;DR crowd. :-) In this case, I wanted to run g++-4.5 on an Ubuntu system that defaults to 4.6. As root:

下面是jHackTheRipper对TL的回答的完整例子;在这种情况下,我想在默认为4.6的Ubuntu系统上运行g++-4.5。作为根用户:

apt-get install g++-4.5
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 100
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.5 50
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 100
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.5 50
update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-4.6 100
update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-4.5 50
update-alternatives --set g++ /usr/bin/g++-4.5
update-alternatives --set gcc /usr/bin/gcc-4.5
update-alternatives --set cpp-bin /usr/bin/cpp-4.5

Here, 4.6 is still the default (aka "auto mode"), but I explicitly switch to 4.5 temporarily (manual mode). To go back to 4.6:

在这里,4.6仍然是默认的(即“自动模式”),但是我显式地暂时切换到4.5(手动模式)。回到4.6:

update-alternatives --auto g++
update-alternatives --auto gcc
update-alternatives --auto cpp-bin

(Note the use of cpp-bin instead of just cpp. Ubuntu already has a cpp alternative with a master link of /lib/cpp. Renaming that link would remove the /lib/cpp link, which could break scripts.)

(注意使用cpp-bin而不是cpp。Ubuntu已经有了一个cpp选项,它的主链接是/lib/ cppp。重命名该链接将删除/lib/cpp链接,这可能会破坏脚本。

#3


14  

This is the great description and step-by-step instruction how to create and manage master and slave (gcc and g++) alternatives.

这是关于如何创建和管理主和从(gcc和g++)选项的详细描述和逐步说明。

Shortly it's:

不久,它是:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.6
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.7
sudo update-alternatives --config gcc

#4


5  

Now, there is gcc-4.9 available for Ubuntu/precise.

现在,gcc-4.9可用于Ubuntu/ precision。

Create a group of compiler alternatives where the distro compiler has a higher priority:

创建一组编译器替代方案,其中发行版编译器具有更高的优先级:

root$ VER=4.6 ; PRIO=60
root$ update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-$VER $PRIO --slave /usr/bin/g++ g++ /usr/bin/g++-$VER
root$ update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-$VER $PRIO

root$ VER=4.9 ; PRIO=40
root$ update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-$VER $PRIO --slave /usr/bin/g++ g++ /usr/bin/g++-$VER
root$ update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-$VER $PRIO

NOTE: g++ version is changed automatically with a gcc version switch. cpp-bin has to be done separately as there exists a "cpp" master alternative.

注意:g++版本会在gcc版本切换时自动更改。cppbin必须单独执行,因为存在“cpp”主选项。

List available compiler alternatives:

列表可用编译器选择:

root$ update-alternatives --list gcc
root$ update-alternatives --list cpp-bin

To select manually version 4.9 of gcc, g++ and cpp, do:

要手动选择gcc、g++和cpp的4.9版本,请执行以下操作:

root$ update-alternatives --config gcc
root$ update-alternatives --config cpp-bin

Check compiler versions:

检查编译器版本:

root$ for i in gcc g++ cpp ; do $i --version ; done

Restore distro compiler settings (here: back to v4.6):

恢复发行版编译器设置(这里:回到v4.6):

root$ update-alternatives --auto gcc
root$ update-alternatives --auto cpp-bin

#5


2  

Between 4.8 and 6 with all --slaves:

在4。8到6之间——奴隶:

update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 \
                    10 \
                    --slave   /usr/bin/cc cc /usr/bin/gcc-4.8 \
                    --slave   /usr/bin/c++ c++ /usr/bin/g++-4.8 \
                    --slave   /usr/bin/g++ g++ /usr/bin/g++-4.8 \
                    --slave   /usr/bin/gcov gcov /usr/bin/gcov-4.8 \
                    --slave   /usr/bin/gcov-dump gcov-dump /usr/bin/gcov-dump-4.8 \
                    --slave   /usr/bin/gcov-tool gcov-tool /usr/bin/gcov-tool-4.8 \
                    --slave   /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-4.8 \
                    --slave   /usr/bin/gcc-nm gcc-nm /usr/bin/gcc-nm-4.8 \
                    --slave   /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-4.8

and

update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 \
                    15 \
                    --slave   /usr/bin/cc cc /usr/bin/gcc-6 \
                    --slave   /usr/bin/c++ c++ /usr/bin/g++-6 \
                    --slave   /usr/bin/g++ g++ /usr/bin/g++-6 \
                    --slave   /usr/bin/gcov gcov /usr/bin/gcov-6 \
                    --slave   /usr/bin/gcov-dump gcov-dump /usr/bin/gcov-dump-6 \
                    --slave   /usr/bin/gcov-tool gcov-tool /usr/bin/gcov-tool-6 \
                    --slave   /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-6 \
                    --slave   /usr/bin/gcc-nm gcc-nm /usr/bin/gcc-nm-6 \
                    --slave   /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-6

Change between them with update-alternatives --config gcc.

在它们之间使用更新替代——config gcc。

#6


1  

I found this problem while trying to install a new clang compiler. Turns out that both the Debian and the LLVM maintainers agree that the alternatives system should be used for alternatives, NOT for versioning.

我在尝试安装新的clang编译器时发现了这个问题。事实证明,Debian和LLVM维护人员都同意,替代系统应该用于替代系统,而不是用于版本控制。

The solution they propose is something like this:
PATH=/usr/lib/llvm-3.7/bin:$PATH
where /usr/lib/llvm-3.7/bin is a directory that got created by the llvm-3.7 package, and which contains all the tools with their non-suffixed names. With that, llvm-config (version 3.7) appears with its plain name in your PATH. No need to muck around with symlinks, nor to call the llvm-config-3.7 that got installed in /usr/bin.

他们提出的解决方案如下:PATH=/usr/lib/llvm-3.7/bin:$PATH,其中/usr/lib/llvm-3.7 bin是llvm-3.7包创建的目录,它包含所有具有非后缀名称的工具。有了这个,llvm-config (version 3.7)在您的路径中出现了它的简单名称。不需要在符号链接上搞乱,也不需要调用安装在/usr/ binin中的llvm-config-3.7。

Also, check for a package named llvm-defaults (or gcc-defaults), which might offer other way to do this (I didn't use it).

另外,检查一个名为llvm-defaults(或gcc-defaults)的包,它可能提供其他方法来实现这一点(我没有使用它)。

#7


0  

In case you want a quicker (but still very clean) way of achieving it for a personal purpose (for instance if you want to build a specific project having some strong requirements concerning the version of the compiler), just follow the following steps:

如果您想要一个更快速(但仍然非常干净)的实现它的方法(例如,如果您想构建一个对编译器版本有一些强烈要求的特定项目),请遵循以下步骤:

  • type echo $PATH and look for a personal directory having a very high priority (in my case, I have ~/.local/bin);
  • 键入echo $PATH并查找具有非常高优先级的个人目录(在我的例子中,我有~/.local/bin);
  • add the symbolic links in this directory:
  • 在此目录中添加符号链接:

For instance:

例如:

ln -s /usr/bin/gcc-WHATEVER ~/.local/bin/gcc
ln -s /usr/bin/g++-WHATEVER ~/.local/bin/g++

Of course, this will work for a single user (it isn't a system wide solution), but on the other hand I don't like to change too many things in my installation.

当然,这对于单个用户来说是可行的(它不是系统范围内的解决方案),但是另一方面,我不喜欢在安装中更改太多的内容。

#8


0  

I used just the lines below and it worked. I just wanted to compile VirtualBox and VMWare WorkStation using kernel 4.8.10 on Ubuntu 14.04. Initially, most things were not working for example graphics and networking. I was lucky that VMWare workstation requested for gcc 6.2.0. I couldn't start my Genymotion Android emulators because virtualbox was down. Will post results later if necessary.

我只用了下面的几行就行了。我只是想在Ubuntu 14.04上使用内核4.8.10来编译VirtualBox和VMWare工作站。最初,大多数东西都不能工作,例如图形和网络。我很幸运,VMWare工作站是为gcc 6.2.0请求的。我无法启动Genymotion Android模拟器,因为virtualbox已经关闭。如有必要,将在稍后公布结果。

VER=4.6 ; PRIO=60
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-$VER $PRIO --slave /usr/bin/g++ g++ /usr/bin/g++-$VER
VER=6 ; PRIO=50
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-$VER $PRIO --slave /usr/bin/g++ g++ /usr/bin/g++-$VER
VER=4.8 ; PRIO=40
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-$VER $PRIO --slave /usr/bin/g++ g++ /usr/bin/g++-$VER

#1


93  

As @Tommy suggested, you should use update-alternatives.
It assigns values to every software of a family, so that it defines the order in which the applications will be called.

正如@Tommy建议的,您应该使用更新替代。它为一个家族的每个软件分配值,以便定义应用程序调用的顺序。

It is used to maintain different versions of the same software on a system. In your case, you will be able to use several declinations of gcc, and one will be favoured.

它用于在系统上维护同一软件的不同版本。在您的情况下,您将能够使用几个gcc的赤纬,其中一个将会受到青睐。

To figure out the current priorities of gcc, type in the command pointed out by @tripleee's comment:

要确定gcc当前的优先级,输入@tripleee的评论指出的命令:

update-alternatives --query gcc

Now, note the priority attributed to gcc-4.4 because you'll need to give a higher one to gcc-3.3.
To set your alternatives, you should have something like this (assuming your gcc installation is located at /usr/bin/gcc-3.3, and gcc-4.4's priority is less than 50):

现在,请注意gcc-4.4的优先级,因为您需要为gcc-3.3提供更高的优先级。要设置备选方案,您应该具有以下内容(假设您的gcc安装位于/usr/bin/gcc-3.3,并且gcc-4.4的优先级小于50):

update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-3.3 50

--edit--

——编辑

Finally, you can also use the interactive interface of update-alternatives to easily switch between versions. Type update-alternatives --config gcc to be asked to choose the gcc version you want to use among those installed.

最后,您还可以使用update-alternatives的交互式接口来轻松地在版本之间切换。键入update-alternative——要求配置gcc来选择要在安装的gcc版本中使用的gcc版本。

--edit 2 --

——编辑2

Now, to fix the CXX environment variable systemwide, you need to put the line indicated by @DipSwitch's in your .bashrc file (this will apply the change only for your user, which is safer in my opinion):

现在,要在整个系统范围内修复CXX环境变量,您需要将@DipSwitch的行放在.bashrc文件中(这只适用于您的用户,在我看来更安全):

echo 'export CXX=/usr/bin/gcc-3.3' >> ~/.bashrc

#2


64  

Here's a complete example of jHackTheRipper's answer for the TL;DR crowd. :-) In this case, I wanted to run g++-4.5 on an Ubuntu system that defaults to 4.6. As root:

下面是jHackTheRipper对TL的回答的完整例子;在这种情况下,我想在默认为4.6的Ubuntu系统上运行g++-4.5。作为根用户:

apt-get install g++-4.5
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 100
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.5 50
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 100
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.5 50
update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-4.6 100
update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-4.5 50
update-alternatives --set g++ /usr/bin/g++-4.5
update-alternatives --set gcc /usr/bin/gcc-4.5
update-alternatives --set cpp-bin /usr/bin/cpp-4.5

Here, 4.6 is still the default (aka "auto mode"), but I explicitly switch to 4.5 temporarily (manual mode). To go back to 4.6:

在这里,4.6仍然是默认的(即“自动模式”),但是我显式地暂时切换到4.5(手动模式)。回到4.6:

update-alternatives --auto g++
update-alternatives --auto gcc
update-alternatives --auto cpp-bin

(Note the use of cpp-bin instead of just cpp. Ubuntu already has a cpp alternative with a master link of /lib/cpp. Renaming that link would remove the /lib/cpp link, which could break scripts.)

(注意使用cpp-bin而不是cpp。Ubuntu已经有了一个cpp选项,它的主链接是/lib/ cppp。重命名该链接将删除/lib/cpp链接,这可能会破坏脚本。

#3


14  

This is the great description and step-by-step instruction how to create and manage master and slave (gcc and g++) alternatives.

这是关于如何创建和管理主和从(gcc和g++)选项的详细描述和逐步说明。

Shortly it's:

不久,它是:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.6
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.7
sudo update-alternatives --config gcc

#4


5  

Now, there is gcc-4.9 available for Ubuntu/precise.

现在,gcc-4.9可用于Ubuntu/ precision。

Create a group of compiler alternatives where the distro compiler has a higher priority:

创建一组编译器替代方案,其中发行版编译器具有更高的优先级:

root$ VER=4.6 ; PRIO=60
root$ update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-$VER $PRIO --slave /usr/bin/g++ g++ /usr/bin/g++-$VER
root$ update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-$VER $PRIO

root$ VER=4.9 ; PRIO=40
root$ update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-$VER $PRIO --slave /usr/bin/g++ g++ /usr/bin/g++-$VER
root$ update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-$VER $PRIO

NOTE: g++ version is changed automatically with a gcc version switch. cpp-bin has to be done separately as there exists a "cpp" master alternative.

注意:g++版本会在gcc版本切换时自动更改。cppbin必须单独执行,因为存在“cpp”主选项。

List available compiler alternatives:

列表可用编译器选择:

root$ update-alternatives --list gcc
root$ update-alternatives --list cpp-bin

To select manually version 4.9 of gcc, g++ and cpp, do:

要手动选择gcc、g++和cpp的4.9版本,请执行以下操作:

root$ update-alternatives --config gcc
root$ update-alternatives --config cpp-bin

Check compiler versions:

检查编译器版本:

root$ for i in gcc g++ cpp ; do $i --version ; done

Restore distro compiler settings (here: back to v4.6):

恢复发行版编译器设置(这里:回到v4.6):

root$ update-alternatives --auto gcc
root$ update-alternatives --auto cpp-bin

#5


2  

Between 4.8 and 6 with all --slaves:

在4。8到6之间——奴隶:

update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 \
                    10 \
                    --slave   /usr/bin/cc cc /usr/bin/gcc-4.8 \
                    --slave   /usr/bin/c++ c++ /usr/bin/g++-4.8 \
                    --slave   /usr/bin/g++ g++ /usr/bin/g++-4.8 \
                    --slave   /usr/bin/gcov gcov /usr/bin/gcov-4.8 \
                    --slave   /usr/bin/gcov-dump gcov-dump /usr/bin/gcov-dump-4.8 \
                    --slave   /usr/bin/gcov-tool gcov-tool /usr/bin/gcov-tool-4.8 \
                    --slave   /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-4.8 \
                    --slave   /usr/bin/gcc-nm gcc-nm /usr/bin/gcc-nm-4.8 \
                    --slave   /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-4.8

and

update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 \
                    15 \
                    --slave   /usr/bin/cc cc /usr/bin/gcc-6 \
                    --slave   /usr/bin/c++ c++ /usr/bin/g++-6 \
                    --slave   /usr/bin/g++ g++ /usr/bin/g++-6 \
                    --slave   /usr/bin/gcov gcov /usr/bin/gcov-6 \
                    --slave   /usr/bin/gcov-dump gcov-dump /usr/bin/gcov-dump-6 \
                    --slave   /usr/bin/gcov-tool gcov-tool /usr/bin/gcov-tool-6 \
                    --slave   /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-6 \
                    --slave   /usr/bin/gcc-nm gcc-nm /usr/bin/gcc-nm-6 \
                    --slave   /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-6

Change between them with update-alternatives --config gcc.

在它们之间使用更新替代——config gcc。

#6


1  

I found this problem while trying to install a new clang compiler. Turns out that both the Debian and the LLVM maintainers agree that the alternatives system should be used for alternatives, NOT for versioning.

我在尝试安装新的clang编译器时发现了这个问题。事实证明,Debian和LLVM维护人员都同意,替代系统应该用于替代系统,而不是用于版本控制。

The solution they propose is something like this:
PATH=/usr/lib/llvm-3.7/bin:$PATH
where /usr/lib/llvm-3.7/bin is a directory that got created by the llvm-3.7 package, and which contains all the tools with their non-suffixed names. With that, llvm-config (version 3.7) appears with its plain name in your PATH. No need to muck around with symlinks, nor to call the llvm-config-3.7 that got installed in /usr/bin.

他们提出的解决方案如下:PATH=/usr/lib/llvm-3.7/bin:$PATH,其中/usr/lib/llvm-3.7 bin是llvm-3.7包创建的目录,它包含所有具有非后缀名称的工具。有了这个,llvm-config (version 3.7)在您的路径中出现了它的简单名称。不需要在符号链接上搞乱,也不需要调用安装在/usr/ binin中的llvm-config-3.7。

Also, check for a package named llvm-defaults (or gcc-defaults), which might offer other way to do this (I didn't use it).

另外,检查一个名为llvm-defaults(或gcc-defaults)的包,它可能提供其他方法来实现这一点(我没有使用它)。

#7


0  

In case you want a quicker (but still very clean) way of achieving it for a personal purpose (for instance if you want to build a specific project having some strong requirements concerning the version of the compiler), just follow the following steps:

如果您想要一个更快速(但仍然非常干净)的实现它的方法(例如,如果您想构建一个对编译器版本有一些强烈要求的特定项目),请遵循以下步骤:

  • type echo $PATH and look for a personal directory having a very high priority (in my case, I have ~/.local/bin);
  • 键入echo $PATH并查找具有非常高优先级的个人目录(在我的例子中,我有~/.local/bin);
  • add the symbolic links in this directory:
  • 在此目录中添加符号链接:

For instance:

例如:

ln -s /usr/bin/gcc-WHATEVER ~/.local/bin/gcc
ln -s /usr/bin/g++-WHATEVER ~/.local/bin/g++

Of course, this will work for a single user (it isn't a system wide solution), but on the other hand I don't like to change too many things in my installation.

当然,这对于单个用户来说是可行的(它不是系统范围内的解决方案),但是另一方面,我不喜欢在安装中更改太多的内容。

#8


0  

I used just the lines below and it worked. I just wanted to compile VirtualBox and VMWare WorkStation using kernel 4.8.10 on Ubuntu 14.04. Initially, most things were not working for example graphics and networking. I was lucky that VMWare workstation requested for gcc 6.2.0. I couldn't start my Genymotion Android emulators because virtualbox was down. Will post results later if necessary.

我只用了下面的几行就行了。我只是想在Ubuntu 14.04上使用内核4.8.10来编译VirtualBox和VMWare工作站。最初,大多数东西都不能工作,例如图形和网络。我很幸运,VMWare工作站是为gcc 6.2.0请求的。我无法启动Genymotion Android模拟器,因为virtualbox已经关闭。如有必要,将在稍后公布结果。

VER=4.6 ; PRIO=60
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-$VER $PRIO --slave /usr/bin/g++ g++ /usr/bin/g++-$VER
VER=6 ; PRIO=50
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-$VER $PRIO --slave /usr/bin/g++ g++ /usr/bin/g++-$VER
VER=4.8 ; PRIO=40
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-$VER $PRIO --slave /usr/bin/g++ g++ /usr/bin/g++-$VER