Skip to content

Conversation

@zhaogewudi666
Copy link

Description

What this PR does

This PR revises the Clang installation instructions to adopt a safer and more maintainable approach.
The documentation now recommends installing Clang into a versioned directory under /usr/local/ (e.g. /usr/local/clang-10.0.0), rather than copying binaries directly into system paths.

Key updates include:
• Clarified the purpose and proper usage of the $PATH environment variable.
• Replaced unsafe guidance involving copying files into /usr/local/bin and /usr/local/lib.
• Added instructions for setting up a dedicated versioned installation directory.
• Improved clarity, accuracy, and long-term maintainability of the document.

Why this change is needed

Copying Clang’s binaries and libraries directly into system directories can:
• pollute system paths
• overwrite existing files
• break version management
• make the installation hard to roll back

Using a versioned directory under /usr/local/ is a widely accepted best practice for managing external binary distributions. It avoids conflicts and allows multiple versions of Clang to coexist cleanly.

How it was tested
• Verified that Clang runs correctly from /usr/local/clang-10.0.0/bin.
• Confirmed PATH modifications behave as expected.
• Ensured that no existing system files are modified or overwritten.

Impact

This PR affects only documentation.
No functional or behavioral changes to the software itself.

Additional notes

If future versions of Clang are added, they can follow the same directory structure without interfering with existing installations.

zhaogewudi666 and others added 2 commits November 28, 2025 15:15
Clarify the recommended installation method for Clang by using a dedicated
directory under /usr/local, instead of copying binaries directly into
system paths. Updated PATH explanation, removed unsafe practices, and
improved overall clarity and maintainability of the documentation.
```

这个目录下的 `clang` 和 `clang++` 就类似于我们比较熟悉的 `gcc` 和 `g++`。这两个是可以直接运行进行编译源代码的可执行文件。当然,我们不能每次在需要编译程序的时候输入如此长的路径找到 `clang` 和 `clang++`,而更希望的是能够像 `apt` 那样在任何地方都可以直接运行。我们可以这样做:
这个目录下的 `clang` 和 `clang++` 就类似于我们比较熟悉的 `gcc` 和 `g++`。这两个是可以直接运行进行编译源代码的可执行文件。当然,我们不能每次在需要编译程序的时候输入如此长的路径找到 `clang` 和 `clang++`,而更希望的是能够像 `apt` 命令那样在任何地方都可以直接运行。我们可以这样做:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里本来实际要表达的意思是「像 apt 安装的程序那样……直接运行」。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那这里的原文应该可以更加清楚明白一些,不然会让人产生和我一样的歧义,认为是像运行 apt 命令一样运行其他命令,虽然这个歧义不会影响全文整体的阅读,但我觉得教材类文章更应该精益求精

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯,可以帮忙改一下。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯嗯,好的,我稍后更新一下 pr

(Output omitted)
```

这个目录下的 `clang` 和 `clang++` 就类似于我们比较熟悉的 `gcc` 和 `g++`。这两个是可以直接运行进行编译源代码的可执行文件。当然,我们不能每次在需要编译程序的时候输入如此长的路径找到 `clang` 和 `clang++`,而更希望的是能够像 `apt` 那样在任何地方都可以直接运行。我们可以这样做:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

要改的话,顺便给 LLVM(clang)升个级如何?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

升级也是有必要的,新版的 Ubuntu/Debian 已经没有 libtinfo.so.5 了。

Copy link
Author

@zhaogewudi666 zhaogewudi666 Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在这里提到针对 LLVM 的升级一事,我建议修改为 16 版本,这个版本较为稳定可靠

```

为什么是 `/usr/local` 呢?因为 `/usr/local/bin` 处在 PATH 环境变量下。当我们在终端输入命令时,终端会先判断是否为终端的内建命令,如果不是,则会在 $PATH 环境变量中包含的目录下进行查找。因此,只要我们将一个可执行文件放入了 $PATH 中的目录下面,我们就可以像 `apt` 一样,在任意地方调用我们的程序。
在这里我们需要知道什么是 `PATH` 变量,当我们在终端输入命令时,终端会先判断是否为终端的内建命令,如果不是,则会在 `$PATH` 环境变量中包含的目录下进行查找。因此,只要我们将一个可执行文件放入了 `$PATH` 中的目录下面,我们就可以像 `apt` 一样,在任意地方调用我们的程序。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一段一行,不要拆开来。

$ sudo mkdir /usr/local/clang-10.0.0
$ # 将 clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04 整个目录复制到新建的 /usr/local/clang-10.0.0 下。
$ sudo cp -R * /usr/local/clang-10.0.0
$ echo 'export PATH=/usr/local/clang-10.0.0/bin:$PATH' >> ~/.bashrc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里删掉 .bashrc 的修改,和下面的重复了。

$ source ~/.bashrc
```

这两条命令将当前 `clang-10.0.0` 目录添加到 PATH 环境变量中。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

换行。

@taoky
Copy link
Member

taoky commented Nov 28, 2025

Description

What this PR does

This PR revises the Clang installation instructions to adopt a safer and more maintainable approach. The documentation now recommends installing Clang into a versioned directory under /usr/local/ (e.g. /usr/local/clang-10.0.0), rather than copying binaries directly into system paths.

Key updates include: • Clarified the purpose and proper usage of the $PATH environment variable. • Replaced unsafe guidance involving copying files into /usr/local/bin and /usr/local/lib. • Added instructions for setting up a dedicated versioned installation directory. • Improved clarity, accuracy, and long-term maintainability of the document.

Why this change is needed

Copying Clang’s binaries and libraries directly into system directories can: • pollute system paths • overwrite existing files • break version management • make the installation hard to roll back

Using a versioned directory under /usr/local/ is a widely accepted best practice for managing external binary distributions. It avoids conflicts and allows multiple versions of Clang to coexist cleanly.

How it was tested • Verified that Clang runs correctly from /usr/local/clang-10.0.0/bin. • Confirmed PATH modifications behave as expected. • Ensured that no existing system files are modified or overwritten.

Impact

This PR affects only documentation. No functional or behavioral changes to the software itself.

Additional notes

If future versions of Clang are added, they can follow the same directory structure without interfering with existing installations.

另外请不要用 AI 生成这么长一段英文描述:没人会看。真的要概括的话,一两句中文就够了。

zhaogewudi666 and others added 5 commits November 29, 2025 17:41
针对之前提交的 pr 对修改内容进行了格式编辑已经 llvm 的版本升级,并修改了关于 apt 的啰嗦内容
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants