Installing and running CLI tools: dart install and dart run pkg@version
suggest changeMany Dart packages ship command-line tools: markdown converts Markdown to HTML, pana scores packages, pubviz draws dependency graphs. The SDK has two newer ways to use them:
dart install(Dart 3.10) installs a package's executables so you can run them by name from any directory. Together withdart installedanddart uninstall, it replacesdart pub global activate.dart run <package>@<version>(Dart 3.12) downloads, compiles and runs a tool in one step, without installing it. It's Dart's version ofnpx.
Both compile the tool ahead of time into native executables using dart build cli, the same compiler that dart compile exe uses.
This article covers:
- writing a tool package with an
executables:section - installing from pub.dev, git or a local directory, with version constraints
- listing, upgrading and uninstalling tools, and name conflicts
- running a tool once with
dart run pkg@version - where the files go and how to put them on
PATHon Windows, macOS and Linux - how this compares with
dart pub global activateand dev dependencies
All commands were run with Dart 3.13.4 on Windows. In the output, the user's home is shown as C:\Users\me and the sample project lives in C:\dev\tally.
A tool package
A tool is an ordinary package with Dart files in bin/. Here is a small one that counts lines, words and characters:
tally/
├── pubspec.yaml
├── bin/
│ ├── tally.dart
│ └── lines.dart
└── lib/
└── tally.dart
name: tally
description: Count lines, words and characters in files.
version: 1.0.0
publish_to: none
environment:
sdk: ^3.10.0
dependencies:
args: ^2.7.0
executables:
tally: # command `tally` runs bin/tally.dart
tally-lines: lines # command `tally-lines` runs bin/lines.dart
// lib/tally.dart
import 'dart:io';
typedef Counts = ({int lines, int words, int chars});
Counts count(String text) => (
lines: '\n'.allMatches(text).length,
words: text.split(RegExp(r'\s+')).where((w) => w.isNotEmpty).length,
chars: text.length,
);
Counts countFile(String path) => count(File(path).readAsStringSync());
// bin/tally.dart
import 'dart:io';
import 'package:args/args.dart';
import 'package:tally/tally.dart';
const version = '1.0.0';
void main(List<String> arguments) {
final parser = ArgParser()
..addFlag('version', negatable: false, help: 'Print the version.');
final args = parser.parse(arguments);
if (args.flag('version')) {
print('tally $version');
return;
}
if (args.rest.isEmpty) {
stderr.writeln('usage: tally <file>...');
exitCode = 64;
return;
}
for (final path in args.rest) {
final c = countFile(path);
print('${c.lines}\t${c.words}\t${c.chars}\t$path');
}
}
// bin/lines.dart
import 'package:tally/tally.dart';
void main(List<String> args) {
for (final path in args) {
print('${countFile(path).lines}\t$path');
}
}
See Command-line arguments for more about package:args.
The executables section
executables: maps command names to files in bin/ (without .dart):
tally:with no value means the command and the file have the same name:bin/tally.dart.tally-lines: linesinstallsbin/lines.dartunder the command nametally-lines.
Only files listed here are installed. Files in bin/ that aren't listed stay private to the package. dart install requires the section. Without it, the install stops:
$ dart install ./mir
The pubspec.yaml contained no executables section.
The mapping is only used by installs. Inside the package, dart run still uses file names:
$ dart run tally notes.txt
3 6 28 notes.txt
$ dart run :tally-lines notes.txt
Could not find `bin\tally-lines.dart` in package `tally`.
$ dart run tally:lines notes.txt
3 notes.txt
Installing a tool with dart install
From the package directory, dart install . compiles every executable and puts a launcher for each on the install bin directory:
C:\dev\tally> dart install .
Generated: c:\users\me\appdata\local\temp\25e6d4df\build\bundle\bin\tally.exe
Generated: c:\users\me\appdata\local\temp\25e6d4df\build\bundle\bin\tally-lines.exe
Installed: C:\Users\me\AppData\Local\Dart\install\bin\tally.bat
Installed: C:\Users\me\AppData\Local\Dart\install\bin\tally-lines.bat
Warning: Dart installs executables into C:\Users\me\AppData\Local\Dart\install\bin\, which is not on your path.
You can fix that by adding that directory to your system's "Path" environment variable.
A web search for "configure windows path" will show you how.
The warning goes away once the directory is on PATH (see Putting the tools on PATH). Then the commands work from anywhere:
C:\dev> where tally
C:\Users\me\AppData\Local\Dart\install\bin\tally.bat
C:\dev> tally --version
tally 1.0.0
C:\dev> tally-lines notes.txt hello.md
3 notes.txt
3 hello.md
The tool is a compiled snapshot of the source at install time. Editing files in C:\dev\tally doesn't change the installed tally. Run dart install . again to rebuild it. You can also delete the source directory and the installed tool keeps working.
Installing from pub.dev, git or a path
The argument is a package name, optionally followed by @ and a descriptor: the same thing you would write for the package under dependencies: in a pubspec.yaml.
# latest stable version from pub.dev
dart install markdown
# version constraints
dart install markdown@7.2.0 # exactly 7.2.0
dart install markdown@^7.0.0 # newest 7.x
dart install 'markdown@<7.3.0' # quote constraints with < or > in the shell
# a custom package server
dart install 'markdown@{hosted: https://pub.example.com, version: ^7.0.0}'
# a package in a subdirectory of a git repository, optionally at a ref
dart install 'markdown@{git: {url: https://github.com/dart-lang/tools, path: pkgs/markdown}}'
dart install 'markdown@{git: {url: https://github.com/dart-lang/tools, path: pkgs/markdown, ref: main}}'
# a local directory
dart install .
dart install ./tally
dart install 'tally@{path: C:/dev/tally}'
Use quotes around YAML descriptors so the shell doesn't interpret {, }, < and >.
A relative path inside a {path: ...} descriptor doesn't work: pub resolves it from a temporary helper package, not from your current directory:
$ dart install 'tally@{path: ./tally}'
Because dart_install_helper_package depends on tally from path which doesn't exist (could not find package tally at "..\..\..\..\..\2f0e0954\helperPackage\tally"), version solving failed.
Use an absolute path, or the plain dart install ./tally form.
Installing from pub.dev:
$ dart install markdown@7.2.0
Generated: c:\users\me\appdata\local\temp\fbf421f\build\bundle\bin\markdown.exe
Installed: C:\Users\me\AppData\Local\Dart\install\bin\markdown.bat
$ markdown --version
7.2.0
Listing installed tools
dart installed lists the packages whose commands are on the install bin directory:
$ dart installed
markdown 7.2.0
tally 1.0.0 from "C:\dev\tally\." at 2026-10-18 00:48:37.506644
Packages installed from a path or git show where they came from, and when.
Upgrading and downgrading
There is no separate upgrade command. Run dart install again with a new version or constraint. The old bundle is removed and the launcher is pointed at the new one:
$ dart install markdown
Generated: c:\users\me\appdata\local\temp\42048891\build\bundle\bin\markdown.exe
Uninstalling C:\Users\me\AppData\Local\Dart\install\app-bundles\markdown\hosted\7.2.0\.
Deleting C:\Users\me\AppData\Local\Dart\install\bin\markdown.bat
Deleting C:\Users\me\AppData\Local\Dart\install\app-bundles\markdown\hosted\7.2.0\
Installed: C:\Users\me\AppData\Local\Dart\install\bin\markdown.bat
$ dart installed
markdown 7.3.1
tally 1.0.0 from "C:\dev\tally\." at 2026-10-18 00:48:37.506644
To downgrade, install an older version: dart install markdown@7.2.0.
Name conflicts and --overwrite
Two packages can't own the same command. Here a different package, other_tally, also declares a tally executable:
$ dart install ./other
Generated: c:\users\me\appdata\local\temp\3bd260ef\build\bundle\bin\tally.exe
Refusing to overwrite executable tally from package:tally. Pass --overwrite to override.
The exit code is 255 and nothing on PATH changes. With --overwrite, the tally command now belongs to other_tally, and dart installed --all shows that the original package lost one of its commands:
$ dart install --overwrite ./other
...
Installed: C:\Users\me\AppData\Local\Dart\install\bin\tally.bat
$ dart installed --all
markdown 7.2.0 (not active)
markdown 7.3.1
other_tally 0.1.0 from "C:\dev\other\." at 2026-10-18 00:47:52.716942
tally 1.0.0 from "C:\dev\tally\." at 2026-10-18 00:46:28.469325 (partially active)
dart installed --all also lists bundles that have no command on PATH ((not active)), for example tools that were only used with dart run pkg@version.
Uninstalling
dart uninstall deletes all installed versions of a package and its launchers:
$ dart uninstall markdown
Deleting C:\Users\me\AppData\Local\Dart\install\app-bundles\markdown\hosted\7.2.0\
Deleting C:\Users\me\AppData\Local\Dart\install\bin\markdown.bat
Deleting C:\Users\me\AppData\Local\Dart\install\app-bundles\markdown\hosted\7.3.1\
$ dart uninstall nope
Did not find any packages named "nope".
Uninstalling the package that took over a command doesn't give the command back to the previous owner. After dart uninstall other_tally, there was no tally command at all, and dart install ./tally had to be run again.
Running a tool once with dart run pkg@version
Outside a package, dart run markdown doesn't know where to find markdown:
$ dart run markdown hello.md
Found no `pubspec.yaml` file in `C:\dev` or parent directories
Add @ and a descriptor to run a tool straight from pub.dev, git or a path:
$ type hello.md
# Hello
Some *emphasis* here.
$ dart run markdown@7.2.0 hello.md
Generated: c:\users\me\appdata\local\temp\6814d420\build\bundle\bin\markdown.exe
<h1>Hello</h1>
<p>Some <em>emphasis</em> here.</p>
The first run resolves the version, downloads the package, compiles it and runs it. That took about 6.5 seconds. The compiled bundle is cached, so the second run took 0.5 seconds:
$ dart run markdown@7.2.0 hello.md
<h1>Hello</h1>
<p>Some <em>emphasis</em> here.</p>
The Generated: line goes to stderr, so it doesn't mix with the tool's own output when you redirect stdout.
The syntax is dart run <package>[:<executable>]@[<descriptor>] [args...]:
dart run markdown@ hello.md # empty descriptor: latest stable version
dart run markdown@7.2.0 hello.md # exact version
dart run 'markdown@^7.0.0' hello.md # constraint
dart run 'markdown@{git: {url: https://github.com/dart-lang/tools, path: pkgs/markdown}}' --version
# pick an executable other than the one named after the package
dart run 'tally:tally-lines@{path: C:/dev/tally}' notes.txt
dart run markdown@ with nothing after @ is not the same as dart run markdown: the @ is what makes it a remote run.
Every argument after the package goes to the tool. VM options such as --enable-asserts are rejected, because the tool runs as a precompiled executable, not in the VM:
$ dart run --enable-asserts markdown@ --version
Option --enable-asserts cannot be used in remote runs. `dart run <remote-executable>` uses `dart install` under the hood and compiles the app into a standalone executable.
The exit code is 64. --verbosity is the only dart run option allowed in remote runs.
Where the cache lives
dart run pkg@version stores bundles in the same place as dart install, but doesn't create launchers on PATH. After a few runs:
$ dart installed --all
markdown 7.2.0 (not active)
markdown 7.3.1 (not active)
tally 1.0.0 from "C:\dev\tally\." at 2026-10-18 00:46:28.469325
The pubspec lock of each cached bundle is compared with a fresh resolution on every run, and the tool is rebuilt only when the resolved versions change. So:
dart run markdown@7.2.0with an exact version reuses the cached build every time.dart run markdown@ordart run 'markdown@^7.0.0'rebuilds when a newer matching version is published.dart install markdownanddart uninstall markdowndelete the cacheddart runbundles ofmarkdowntoo.
Pinning tools in scripts and CI
Because dart run pkg@version needs nothing but the SDK, it's a convenient way to use a tool in a script or CI job without a global install step. Pin an exact version so every run uses the same tool:
# .github/workflows/docs.yml
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: dart-lang/setup-dart@v1
- run: dart run markdown@7.3.1 README.md > README.html
Where the files go
The install directory comes from the Dart data home:
| OS | Default install directory |
|---|---|
| Windows | %LOCALAPPDATA%\Dart\install |
| macOS | $HOME/Library/Application Support/Dart/install |
| Linux | $XDG_STATE_HOME/Dart/install, or $HOME/.local/state/Dart/install if XDG_STATE_HOME isn't set |
Set the DART_DATA_HOME environment variable to move it: tools then go to $DART_DATA_HOME/install. That's useful for a sandboxed CI cache, or to try installs without touching your real setup:
# PowerShell
$env:DART_DATA_HOME = "C:\temp\dart-data"
dart install markdown
# Installed: C:\temp\dart-data\install\bin\markdown.bat
Inside the install directory:
install/
├── bin/ <- put this on PATH
│ ├── markdown.bat
│ ├── tally.bat
│ └── tally-lines.bat
└── app-bundles/
├── markdown/
│ └── hosted/7.3.1/
│ ├── pubspec.yaml
│ ├── pubspec.lock
│ └── bundle/bin/markdown.exe
└── tally/
└── local/
├── pubspec.yaml
├── pubspec.lock
└── bundle/bin/
├── tally.exe
└── tally-lines.exe
Each bundle is self-contained: the executables don't need the Dart SDK to run. On Windows, each command in bin/ is a small .bat launcher:
@ECHO OFF
REM target_file_path_marker
"C:\Users\me\AppData\Local\Dart\install\app-bundles\markdown\hosted\7.3.1\bundle\bin\markdown.exe" %*
EXIT /B %ERRORLEVEL%
On macOS and Linux, entries in bin/ are symbolic links to the executables in the bundle.
Putting the tools on PATH
Add the bin directory once.
Windows (PowerShell; changes the user Path, takes effect in new terminals):
$bin = "$env:LOCALAPPDATA\Dart\install\bin"
$path = [Environment]::GetEnvironmentVariable('Path', 'User')
[Environment]::SetEnvironmentVariable('Path', "$path;$bin", 'User')
Or use Settings > System > About > Advanced system settings > Environment Variables and add %LOCALAPPDATA%\Dart\install\bin to the user Path.
macOS (zsh, the default shell), in ~/.zshrc:
export PATH="$PATH:$HOME/Library/Application Support/Dart/install/bin"
Linux (bash), in ~/.bashrc, or ~/.zshrc for zsh:
export PATH="$PATH:${XDG_STATE_HOME:-$HOME/.local/state}/Dart/install/bin"
Open a new terminal and check with where tally (Windows) or command -v tally (macOS, Linux).
dart pub global activate uses a different directory: %LOCALAPPDATA%\Pub\Cache\bin on Windows and ~/.pub-cache/bin elsewhere (or $PUB_CACHE/bin). If you use both commands, both directories need to be on PATH.
dart install vs dart pub global activate
dart pub global activate still works. The differences:
dart install |
dart pub global activate |
|
|---|---|---|
| Compiles to | native AOT executable | JIT snapshot run by the dart VM |
| Needs the SDK to run the tool | no | yes, the launcher calls dart pub global run |
bin directory |
Dart data home install/bin |
pub cache bin |
Requires executables: |
yes | no, dart pub global run pkg:file works without it |
| Local directory | snapshot of the source at install time | --source path runs the live source |
dart:mirrors |
not supported (AOT) | supported |
VM flags such as --enable-asserts |
no | yes, via dart pub global run |
| List / remove | dart installed / dart uninstall |
dart pub global list / deactivate |
The path-activated case shows the biggest practical difference. The launcher pub global activate writes on Windows is:
@echo off
rem This file was created by pub v3.13.4.
rem Package: tally
rem Version: 1.0.0
rem Executable: tally
rem Script: tally
call dart pub global run tally:tally %*
It re-resolves the package and recompiles changed code on every run, which is handy while you are developing the tool, but slower. On this machine that took about 0.9 seconds per run, compared with about 0.15 seconds for the dart install version of the same tool:
C:\dev> %LOCALAPPDATA%\Pub\Cache\bin\tally.bat notes.txt
Resolving dependencies...
Downloading packages...
No dependencies would change in `C:\dev\tally`.
3 6 28 notes.txt
C:\dev> %LOCALAPPDATA%\Dart\install\bin\tally.bat notes.txt
3 6 28 notes.txt
For a tool activated from pub.dev, the JIT snapshot also starts quickly, so the startup times were close.
AOT compilation is also why some tools can't be installed with dart install. A tool that imports dart:mirrors fails to build:
$ dart install ./mir
mir/bin/mir.dart:1:8: Error: Dart library 'dart:mirrors' is not available on this platform.
import 'dart:mirrors';
^
Bad state: Generating AOT kernel dill failed!
The same package works with dart pub global activate. Code that finds its own files with Platform.script or Isolate.resolvePackageUri also behaves differently when compiled; see Compiling to executables for AOT limitations. Packages with build hooks (native assets) are supported, since dart install builds with dart build cli.
Global tools vs dev dependencies
Tools that a project depends on, such as build_runner or a code generator, belong in the project's dev_dependencies, not in a global install:
dart pub add dev:build_runner
dart run build_runner build
The version is then recorded in pubspec.lock, so everyone on the team and CI run the same version. In a monorepo, put shared tools in the workspace root's dev_dependencies; see Pub workspaces (monorepos).
A rough rule:
- tool used by one project: dev dependency and
dart run <tool> - tool used once, or in a CI step outside a project:
dart run <tool>@<version> - tool you use every day from any directory:
dart install <tool> - tool for people without the Dart SDK:
dart compile exeand ship the binary
Summary
| Task | Command |
|---|---|
| Declare commands in a package | executables: in pubspec.yaml: name: or name: file |
| Install from pub.dev | dart install markdown |
| Install a version | dart install markdown@7.2.0, dart install 'markdown@^7.0.0' |
| Install from git | dart install 'pkg@{git: {url: ..., path: ..., ref: ...}}' |
| Install the current package | dart install . |
| Replace another package's command | dart install --overwrite ... |
| Upgrade | run dart install again |
| List | dart installed, dart installed --all |
| Remove | dart uninstall markdown |
| Run once, without installing | dart run markdown@7.2.0 file.md |
| Run a specific executable | dart run 'pkg:exe@<descriptor>' |
| Latest version, once | dart run markdown@ |
| Move the install directory | DART_DATA_HOME |
Directory to put on PATH |
%LOCALAPPDATA%\Dart\install\bin, ~/Library/Application Support/Dart/install/bin, ~/.local/state/Dart/install/bin |