DEV Community

阿豪
阿豪

Posted on

Building and Installing Neovim on OpenWrt

Pre-compiled Neovim binaries fail on OpenWrt with interpreter/linker errors:

ei https://github.com/neovim/neovim/releases/download/nightly/nvim-linux-x86_64.tar.gz
nvim
# Error: Failed to execute process: The file exists and is executable.
# Check the interpreter or linker?
Enter fullscreen mode Exit fullscreen mode

This happens due to glibc/musl incompatibility. Building from source ensures compatibility with OpenWrt's musl libc.

Prerequisites

This guide uses OpenWrt 24.10.4 x86_64. For other versions, refer to the original guide.

Installing Dependencies

Install the required build tools and libraries:

opkg update
opkg install git git-http python3 python3-pip make luajit gcc coreutils-install
pip install cmake
Enter fullscreen mode Exit fullscreen mode

Fixing Missing Libraries

OpenWrt's minimal environment lacks some standard libraries that Neovim expects.

Fix Missing libdl

The dynamic linker library is built into musl but needs a stub for linking:

printf "!<arch>\n" > /usr/lib/libdl.a
Enter fullscreen mode Exit fullscreen mode

This creates an empty archive that satisfies the linker without adding actual code (musl already provides dlopen and friends).

Fix Missing libutil

Create a dummy shared library for the utility functions:

echo "int main() { return 0; }" > dummy.c
gcc -shared -o /usr/lib/libutil.so dummy.c
rm dummy.c
Enter fullscreen mode Exit fullscreen mode

Most libutil functions (like forkpty) are either unused by Neovim or provided by other libraries on musl systems.

Building Neovim

Clone the repository (shallow clone to save space):

git clone https://github.com/neovim/neovim --depth=1
cd neovim
Enter fullscreen mode Exit fullscreen mode

Build with release optimizations and debug symbols:

make CMAKE_BUILD_TYPE=RelWithDebInfo
Enter fullscreen mode Exit fullscreen mode

This takes 10-30 minutes depending on your system. The RelWithDebInfo build type provides good performance while keeping some debug information for troubleshooting.

Installing Neovim

Install to the default location:

make install
Enter fullscreen mode Exit fullscreen mode

This installs to /usr/local/bin/nvim. Create a symlink for convenience:

ln -sf /usr/local/bin/nvim /usr/bin/nvim
Enter fullscreen mode Exit fullscreen mode

Verify the installation:

nvim --version
Enter fullscreen mode Exit fullscreen mode

Setting Up LazyVim

LazyVim is a modern Neovim configuration with sensible defaults and a plugin manager.

git clone https://github.com/LazyVim/starter --depth=1 ~/.config/nvim
Enter fullscreen mode Exit fullscreen mode

On first launch, Neovim will automatically install plugins:

nvim
Enter fullscreen mode Exit fullscreen mode

Installing tmux

opkg install tmux
Enter fullscreen mode Exit fullscreen mode

Top comments (0)