问题
这个问题以及包含解决该问题的各种方法的答案几乎每天都会在我们的交流中多次出现。如果搜索结果将您带到这里欢迎!如果我在链接到您的问题中留下的评论,您可以放心地假设您的问题可以添加到下面的列表中,因为它属于同一类别:
- gcc降级后glib和gcc之间的分歧
- 如何在 Fedora 39 上降级到特定的 gcc 版本?
- 如何在 arch linux 中安装一些 gcc 编译器?
- Debian Bullseye:安装 gcc-11.4.0 和依赖项
这些只是[gcc]
搜索词降级所标记的众多问题中的四个。那些知识渊博、能够先来交流的读者/用户几乎总是会问我怎样才能……”那些尝试过失败的不幸读者几乎总是会说“它坏了”,或者“我想我坏了一些东西”。这个问题和答案,我将尝试解释为什么混合编译器会破坏所有Linux,并且在答案中我将提供我所知道的解决问题的最简单方法,这不会导致损坏,但会花费一些开销设置的时间和空间。由于这将是社区贡献的问答,如果您喜欢我的方法,我恳请您投票。
问题解释
TLDR:跳至为什么降级编译器会导致问题?
我在各种答案中使用了下面的图片两到三次,我觉得它为我们所有人提供了一个很好的起点。我意识到它很大,因此,如果您愿意,我敦促读者在单独的选项卡中打开它并进行缩放等。
在该列表中找到您的发行版,然后继续阅读。您会注意到您的发行版有一个父发行版。好吧,好吧,我知道使用父发行版(时间轴最左边的发行版)的读者会问:
我正在使用最左边的一个,那么它的父母在哪里?
现在我们进入这个问题的核心。例如,让我们填写$X
我$Y
的标题(耐心的读者,$Z
即将出现)
$X = Fedora 39
$Y = 13.2.1-6.fc39
定义
- Distribution (Quoting Wikipedia):
A Linux distribution (often abbreviated as distro) is an operating system made from a software collection that includes the Linux kernel and often a package management system.
- Package Management System (Quoting Again):
A package manager or package-management system is a collection of software tools that automates the process of installing, upgrading, configuring, and removing computer programs for a computer in a consistent manner
Knowing these two items helps us answer the Parent Distribution question, but unfortunately with another question: How Do the distribution maintainers create a distribution?
The Answer: All linux software minus the kernel is stored at and can be obtained from the GNU Software FTP Site in source code archives. All Linux Kernels are available for download in source code archives at The Linux Kernel Archives. In short, all Distributions begin from the same source code, including the parent distributions
Why Does Downgrading Compilers Cause Issues?
From the definition earlier, a distribution is a group or set of related software. This relation can be seen in your distribution's repository (or whatever else your distribution has chosen to name it).
At the time a new version (in our Example $X
= Fedora 39) is made available the repository for that version is locked, specifically version locked, meaning that every package in that repository is now frozen in time. Once frozen it isn't altered. It can only live as long as the version is supported or die when the version is upgraded.
The tools required to build GCC are also in the now frozen repository. If a user attempts to upgrade or downgrade the GCC that was shipped in the frozen repository, the version locking would be broken if you were to succeed. To prevent the breakage from happening, your OS'es Package Manager prevents this.
Read my answer to find out how I overcame $Z
A less heavyweight solution is to use containers. Install Docker or Podman, and follow the recipe in eyoung100’s answer to identify the distribution release you’re after, or look it up on Repology.
Using the same Fedora 36 example, run a container:
您可以添加
-v
选项以使系统上的目录在容器内可用:(仅
:z
当您使用 SELinux 时才添加)。在容器中,安装
gcc
您需要的任何其他工具,构建您的项目(在 中/myproject
),然后您将在共享的目录中找到您的文件。My Solution
First off, I guess I would be considered a purist in that if a package isn't in your repository, or can't be added from a third party repository, you shouldn't attempt to compile it from scratch or "force it to work" because doing so short-circuits your package manager. With that in mind, I present a rock-solid solution
Virtualization Is Our Friend
We need some tools and a bit of Hard Drive Space for this approach. I'll leave making space available to you but aside from that follow these steps:
Note: Vagrant will work with Hyper-V and docker out of the box I believe (see Stephen Kitt's answer for help with docker), but I chose VirtualBox because that's what I learned first, and if needed I can install a Desktop in the VM to configure the VM further.
With our Virtualization Helpers installed we can continue. I'm continuing by:
$Z
now. Using Example question 2 from the Issue heading above we have the following values:$X = Fedora
$Y = 13.2.1-6.fc39
$Z = 12.x.x
So using our example: Which release of Fedora contained GCC 12. Now Quoting Google:
$X release history
Which would equate to Fedora release history in our example, which gives us Fedora Linux release history. Well, what do we do now? It looks like Fedora 36 is no longer supported. We added Vagrant for this very reason. If we visit The Vagrant Cloud, we can search for Fedora 36, which yields these results, and using a Vagrantfile, we can customize a full VM version and develop our application or website using the VM while saving our project files on our host system.
Reason Why I Chose This Approach
Using virtualization separates your development environment from the system you use day-to-day, and keeps you from making an irreparable mistake. I realize it will cost a bit of extra setup time, but Vagrant only needs to be installed once. A vagrantfile only needs to be created each time your project requirements change. The small learning curve for Vagrant and the Virtualization is worth the tradeoff of reinstalling an OS if a mistake is made trying to figure out how to install multiple compilers.