The Tree-sitter CLI is required to create and develop Tree-sitter parsers. There are several ways to install it.
Prerequisites
Before installing the Tree-sitter CLI, ensure you have:
-
A JavaScript runtime - Tree-sitter grammars are written in JavaScript. The CLI requires Node.js (or another JavaScript runtime) to interpret grammar files. The runtime command (default:
node) must be in your PATH.
-
A C Compiler - Tree-sitter creates parsers written in C. To compile and test parsers, you need a C/C++ compiler installed. The CLI will look for compilers in the standard platform locations.
Installation Methods
Cargo (Recommended)
Install from crates.io using Rust’s package manager:
This method works on all platforms and provides the latest version.
Build from Source
Build the CLI from source using Cargo:
See the contributing docs for more information.
NPM
Install the Node.js module using npm:
This approach is fast but only works on certain platforms as it relies on pre-built binaries.
Pre-built Binaries
Download a binary for your platform from GitHub releases and add it to your PATH.
Verifying Installation
After installation, verify the CLI is available:
You should see output showing the version number.
Next Steps
Once installed, you can:
- Initialize a new parser project with
tree-sitter init
- Create a config file with
tree-sitter init-config
- Start developing your grammar
macOS/iOS
You can set MACOSX_DEPLOYMENT_TARGET or IPHONEOS_DEPLOYMENT_TARGET to define the minimum supported version when building parsers.
Windows
The CLI works on Windows but some safety checks (like symbol validation with nm) are not performed.