
title=”HarmonyOS PC openEuler 常用于开发软件” frameborder=”0” allow=”accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share” referrerpolicy=”strict-origin-when-cross-origin” allowfullscreen>
在HarmonyOS PC融合开发引擎的openEuler容器中,尝试安装nvim-treesitter插件时遇到错误:
[nvim-treesitter/install/c] error: Error during “tree-sitter build”: tree-sitter: /usr/lib64/libc.so.6: version `GLIBC_2.39’ not found (required by tree-sitter)
ldd --version # 输出:ldd (GNU libc) 2.38 cat /etc/os-release # NAME=”openEuler” # VERSION=”24.03 (LTS-SP1)”
openEuler 24.03 SP1的glibc版本为2.38,而nvim-treesitter下载的预编译tree-sitter CLI需要glibc 2.39。
容器环境共享虚拟机内核,无法升级glibc。解决方案是从源代码编译所有组件,使用当前系统的glibc版本。
1. 安装编译依赖 2. 安装Rust工具链(编译tree-sitter CLI需要) 3. 从源码编译tree-sitter CLI 4. 从源码编译Neovim 5. 配置AstroNvim
# 安装cmake和ninja sudo dnf install -y cmake ninja-build # 验证安装 cmake --version ninja --version
# gcc、make等已预装 gcc --version make --version
tree-sitter CLI 是用 Rust 编写的,需要先安装:
# 设置代理(可选) export https_proxy=http://192.168.3.6:1080 # 安装Rust curl --proto ‘=https’ -sSf https://sh.rustup.rs | sh -s -- -y # 加载环境 source ~/.cargo/env # 验证 cargo --version rustc --version
export https_proxy=http://192.168.3.6:1080 # 克隆tree-sitter CLI(使用稳定版本v0.24.1) git clone --depth 1 --branch v0.24.1 \ https://github.com/tree-sitter/tree-sitter.git \ ~/tree-sitter-cli
cd ~/tree-sitter-cli cargo build --release
编译过程大约需要 1-2 分钟。
# 系统安装 sudo cp ~/tree-sitter-cli/target/release/tree-sitter /usr/local/bin/ # 或替换mason的预编译版本 cp ~/tree-sitter-cli/target/release/tree-sitter \ ~/.local/share/nvim/mason/packages/tree-sitter-cli/tree-sitter-linux-arm64 # 验证 tree-sitter --version # 输出:tree-sitter 0.24.1
export https_proxy=http://192.168.3.6:1080
# 查看最新版本
git ls-remote --tags https://github.com/neovim/neovim.git | \
grep -v ‘\^{}’ | grep ‘v0\.1[0-2]’ | tail -5
# 克隆最新稳定版v0.12.0
git clone --depth 1 --branch v0.12.0 \
https://github.com/neovim/neovim.git \
~/neovimcd ~/neovim make CMAKE_BUILD_TYPE=Release
编译过程大约需要 3-5 分钟,并会自动下载和编译所有依赖项。
sudo make install # 验证 nvim --version # 输出: # NVIM v0.12.0 # Build type: Release # LuaJIT 2.1.1774638290
ls ~/neovim/build/bin/nvim # -rwxr-xr-x 1 user user 10346568 ... nvim
AstroNvim 是一个预配置的 Neovim 发行版,提供完整的 IDE 体验。
# 备份旧配置 mv ~/.config/nvim ~/.config/nvim.bak mv ~/.local/share/nvim ~/.local/share/nvim.bak mv ~/.local/state/nvim ~/.local/state/nvim.bak
# 克隆AstroNvim配置 git clone --depth 1 https://github.com/AstroNvim/AstroNvim \ ~/.config/nvim # 复制默认用户配置模板 cp ~/.config/nvim/lua/user_template.lua ~/.config/nvim/lua/user.lua
nvim
首次启动会自动安装所有插件和 tree-sitter 解析器。由于我们已经编译了 tree-sitter CLI,treesitter 安装不会出现 glibc 错误。
编辑:~/.config/nvim/lua/user.lua
return {
-- 自定义颜色方案
colorscheme = “catppuccin-mocha”,
-- 自定义选项
options = {
opt = {
relativenumber = true, -- 相对行号
},
},
-- 自定义插件
plugins = {
“rebelot/kanagawa.nvim”,
-- 添加更多插件...
},
-- LSP配置
lsp = {
formatting = {
format_on_save = true,
},
servers = {
-- 添加LSP服务器...
},
},
}:LspInstall python :LspInstall lua_ls :TSInstall python :TSInstall lua :MasonInstall prettier
:TSInstallInfo
查看可用的解析器并选择所需的安装:
:TSInstall vimdoc :TSInstall lua :TSInstall python :TSInstall javascript :TSInstall html :TSInstall css :TSInstall json :TSInstall markdown
:TSInstallInfo
所有解析器都应显示为 . ✓ 已安装
组件 版本 状态 cmake 3.27.9
✓ 已安装ninja1.11.1
✓ 已安装Rust1.94.1
✓ 已安装tree-sitter CLI0.24.1
✓ 已编译 Neovim0.12.0
✓ 已编译 Astro Nvim 最新版
glibc 兼容:从源码编译可确保使用当前 glibc
Rust 依赖:tree-sitter CLI 需要 Rust 编译
完整流程:依赖 → Rust → tree-sitter → Neovim → AstroNvim
编译后的 Neovim 在 openEuler 容器中运行流畅:
启动速度:< 100ms
LSP 响应:快速
Treesitter 高亮:正常
插件生态:完全支持
不要使用预编译的 tree-sitter:mason 下载的预编译版本与 glibc 不兼容
记得替换 Mason 的 tree-sitter:否则 nvim-treesitter 仍会使用预编译版本
使用稳定版本:避免 main 分支的不稳定性
编译完成后,可以清理源代码:
# 可选:保留源码用于后续升级 # 或删除以节省空间 rm -rf ~/tree-sitter-cli rm -rf ~/neovim
建议保留源代码目录,以便后续版本升级。
cd ~/neovim git fetch --tags git checkout v0.13.0 # 假设新版本 make CMAKE_BUILD_TYPE=Release sudo make install
升级 tree-sitter:
cd ~/tree-sitter-cli git fetch --tags git checkout v0.25.0 # 假设新版本 cargo build --release sudo cp target/release/tree-sitter /usr/local/bin/
Neovim 官方网站:
tree-sitter 项目:
https://tree-sitter.github.io
AstroNvim 文档:
https://astronvim.com
AstroNvim 仓库:https://github.com/AstroNvim/AstroNvim
转载声明:本文为转载整理,原文版权归原作者及原站点所有。
原创地址:https://www.harmony-developers.com/p/compile-and-install-the-neovim-and
原文作者:Harmony OS Developers;如有侵权,请联系管理员删除。