How to install Neovim on Apple Silicon M1 Mac

Takuya Matsuyama - Jan 4 '21 - - Dev Community

TL;DR

Do this:

xcode-select --install
brew install --HEAD tree-sitter
brew install --HEAD luajit
brew install --HEAD neovim
Enter fullscreen mode Exit fullscreen mode

My work log

Yesterday, my M1 Macbook Air has arrived and I started setting it up.
But I encountered an error when installing Neovim via Homebrew. It doesn't simply let me install with brew install neovim because the formula doesn't exist for M1 macs.

I found that Neovim developers have already worked on it and you can install like so:

brew install --HEAD neovim
Enter fullscreen mode Exit fullscreen mode

but it failed:

...
==> Installing dependencies for neovim: tree-sitter, cmake, lua, luarocks, unibilium, libtermkey, libuv, libvterm, luajit and msgpack
==> Installing neovim dependency: tree-sitter
==> make
==> make install PREFIX=/opt/homebrew/Cellar/tree-sitter/0.17.3
==> cargo install
Last 15 lines from /Users/***/Library/Logs/Homebrew/tree-sitter/03.cargo:
  thread 'main' panicked at '

  Internal error occurred: Command "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=aarch64-apple-darwin" "-I" "src" "-I" "include" "-Wall" "-Wextra" "-o" "/private/tmp/tree-sitter-20210103-22123-s208p2/tree-sitter-0.17.3/target/release/build/tree-sitter-622599610e6262f9/out/src/lib.o" "-c" "src/lib.c" with args "clang" did not execute successfully (status code exit code: 1).

  ', /Users/***/Library/Caches/Homebrew/cargo_cache/registry/src/github.com-1ecc6299db9ec823/cc-1.0.25/src/lib.rs:2260:5
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
The following warnings were emitted during compilation:

warning: error: unknown target triple 'unknown-apple-macosx11.0.0', please use -triple or -arch

error: failed to compile `tree-sitter-cli v0.17.3 (/private/tmp/tree-sitter-20210103-22123-s208p2/tree-sitter-0.17.3/cli)`, intermediate artifacts can be found at `/private/tmp/tree-sitter-20210103-22123-s208p2/tree-sitter-0.17.3/target`

Caused by:
  build failed

Do not report this issue to Homebrew/brew or Homebrew/core!
Enter fullscreen mode Exit fullscreen mode

Looks like a dependency tree-sitter was failed to build.
Ok, let's install it from HEAD:

brew install --HEAD tree-sitter
==> Cloning https://github.com/tree-sitter/tree-sitter.git
Cloning into '/Users/***/Library/Caches/Homebrew/tree-sitter--git'...
==> Checking out branch master
Already on 'master'
Your branch is up to date with 'origin/master'.
==> make
==> make install PREFIX=/opt/homebrew/Cellar/tree-sitter/HEAD-115bf3f
==> cargo install
🍺  /opt/homebrew/Cellar/tree-sitter/HEAD-115bf3f: 14 files, 5.0MB, built in 42 seconds
Removing: /Users/***/Library/Caches/Homebrew/tree-sitter--0.17.3.tar.gz... (506.8KB)
Enter fullscreen mode Exit fullscreen mode

Ok, it worked.
But then, luajit failed to install:

🍺  /opt/homebrew/Cellar/libvterm/0.1.4: 12 files, 393KB
==> Installing neovim dependency: luajit
==> Patching
Warning: Calling ENV.O2 is deprecated! There is no replacement.
Please report this issue to the homebrew/core tap (not Homebrew/brew or Homebrew/core):
  /opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/luajit.rb:43

==> make amalg PREFIX=/opt/homebrew/Cellar/luajit/2.0.5
Last 15 lines from /Users/***/Library/Logs/Homebrew/luajit/01.make:
#error "Need at least GCC 4.3 or newer"
 ^
3 errors generated.
lj_arch.h:55:2: error: "No support for this architecture (yet)"
#error "No support for this architecture (yet)"
 ^
lj_arch.h:294:2: error: "No target architecture defined"
#error "No target architecture defined"
 ^
lj_arch.h:317:2: error: "Need at least GCC 4.3 or newer"
#error "Need at least GCC 4.3 or newer"
 ^
3 errors generated.
Makefile:254: *** Unsupported target architecture.  Stop.
make: *** [amalg] Error 2
Enter fullscreen mode Exit fullscreen mode

Alright, let's install it also from HEAD:

/opt/homebrew/bin/brew install --HEAD luajit
==> Cloning https://luajit.org/git/luajit-2.0.git
Updating /Users/***/Library/Caches/Homebrew/luajit--git
==> Checking out branch v2.1
Already on 'v2.1'
Your branch is up to date with 'origin/v2.1'.
HEAD is now at 1e66d0f9 Merge branch 'master' into v2.1
Warning: Calling ENV.O2 is deprecated! There is no replacement.
Please report this issue to the homebrew/core tap (not Homebrew/brew or Homebrew/core):
  /opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/luajit.rb:43

==> make amalg PREFIX=/opt/homebrew/Cellar/luajit/HEAD-1e66d0f XCFLAGS=-DLUAJIT_ENABLE_GC64
==> make install PREFIX=/opt/homebrew/Cellar/luajit/HEAD-1e66d0f XCFLAGS=-DLUAJIT_ENABLE_GC64
🍺  /opt/homebrew/Cellar/luajit/HEAD-1e66d0f: 37 files, 2.3MB, built in 11 seconds
Enter fullscreen mode Exit fullscreen mode

Cool. Now, try installing neovim again:

/opt/homebrew/bin/brew install --HEAD neovim
==> Downloading https://homebrew.bintray.com/bottles/msgpack-3.3.0.arm64_big_sur.bottle.tar.gz
Already downloaded: /Users/***/Library/Caches/Homebrew/downloads/780553bf2083258555b13aeea05333331a9a541f819afac70c31ffcf78ecd2ed--msgpack-3.3.0.arm64_big_sur.bottle.tar.gz
==> Downloading https://github.com/libmpack/libmpack-lua/releases/download/1.0.8/libmpack-lua-1.0.8.tar.gz
Already downloaded: /Users/***/Library/Caches/Homebrew/downloads/4b91349796a66e38e93acd77e6ca14212c869090429fd88271def2be5293d83f--libmpack-lua-1.0.8.tar.gz
==> Downloading https://luarocks.org/manifests/gvvaughan/lpeg-1.0.2-1.src.rock
Already downloaded: /Users/***/Library/Caches/Homebrew/downloads/0bc17975f0cf3981083172aa7da329b874e5780fa81494f5dd07d0665fcec23b--lpeg-1.0.2-1.src.rock
==> Downloading https://luarocks.org/manifests/kikito/inspect-3.1.1-0.src.rock
Already downloaded: /Users/***/Library/Caches/Homebrew/downloads/ecc1fa84ce4c83c9406f6d1202d4a88c80ede4a0a2bfd8d8d2bd54fd042226bb--inspect-3.1.1-0.src.rock
==> Downloading https://github.com/keplerproject/lua-compat-5.3/archive/v0.7.tar.gz
Already downloaded: /Users/***/Library/Caches/Homebrew/downloads/5f4e552e95b9a6223a5e4fabb7f04bf4b886057024507c76b1d5b803218c9363--lua-compat-5.3-0.7.tar.gz
==> Downloading https://github.com/luvit/luv/releases/download/1.30.0-0/luv-1.30.0-0.tar.gz
Already downloaded: /Users/***/Library/Caches/Homebrew/downloads/a9ce5a949370965d8f0fe70a47e7d102a3b4b6b831dbd4d088a83bbe1c00a3a2--luv-1.30.0-0.tar.gz
==> Cloning https://github.com/neovim/neovim.git
Updating /Users/***/Library/Caches/Homebrew/neovim--git
==> Checking out branch master
Already on 'master'
Your branch is up to date with 'origin/master'.
HEAD is now at 7a81a0c Merge pull request #13665 from janlazo/vim-8.2.0917
==> Installing dependencies for neovim: msgpack
==> Installing neovim dependency: msgpack
==> Pouring msgpack-3.3.0.arm64_big_sur.bottle.tar.gz
🍺  /opt/homebrew/Cellar/msgpack/3.3.0: 757 files, 5.3MB
==> Installing neovim --HEAD
==> luarocks make --lua-dir=/opt/homebrew/opt/luajit --tree=/private/tmp/neovim-20210103-14924-bnufr5/deps-build
==> luarocks make --lua-dir=/opt/homebrew/opt/luajit --tree=/private/tmp/neovim-20210103-14924-bnufr5/deps-build
==> luarocks make --lua-dir=/opt/homebrew/opt/luajit --tree=/private/tmp/neovim-20210103-14924-bnufr5/deps-build
==> cmake . -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DCMAKE_INSTALL_PREFIX=/private/tmp/neovim-20210103-14924-bnufr5/deps-build -DLUA_BUILD_TYPE=System -DWITH_SHARED_LIBUV=
==> make install
==> cmake .. -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DLIBLUV_INCLUDE_DIR=/private/tmp/neovim-20210103-14924-bnufr5/deps-build/include -DLIBLUV_LIBRARY=/private/tmp/neovim-
==> make install
🍺  /opt/homebrew/Cellar/neovim/HEAD-7a81a0c: 1,452 files, 21.3MB, built in 31 seconds
Enter fullscreen mode Exit fullscreen mode

Gotcha~

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .