Global is one of the commands of the pub tool. Learn more about pub.
global option allows you to run Dart scripts from the
command line when you are not currently inside a package.
You first activate a package, then you can
run scripts from that package’s bin directory.
Deactivating a package removes it from
your list of globally available packages.
To run a Dart script from within a package, or from a package that your package depends on, see pub run.
$ pub global activate [--noexecutables] [--executable=<name>] [--overwrite] <package> [constraint]
activate to enable you to run a package’s executables
from anywhere on your machine.
You can activate a package on pub.dartlang.org,
in a Git repository, or on your local machine.
Once you have activated a package, see Running a script
to run scripts from the package’s
When you activate a package you can specify an optional constraint. See the constraint flag for usage examples.
$ pub global activate <pub.dartlang package>
Specify a package on pub.dartlang.org to activate it. For example:
$ pub global activate markdown
$ pub global activate --source git <Git URL> $ pub global activate -sgit <Git URL>
--source git (or
-sgit, for short) to activate
a package in a Git repository. The following examples,
which activate the
async_await package on
GitHub, are equivalent:
pub global activate --source git https://github.com/dart-lang/async_await.git pub global activate -sgit https://github.com/dart-lang/async_await.git
$ pub global activate --source path <path>
activate --source path <path> to activate a package on your local machine.
The following example activates the
stopwatch package from the
pub global activate --source path ~/dart/stopwatch
Once a package has been activated, you can upgrade it by activating the package again.
You can run a script from an activated package explicitly using
pub global run, or you can add it to your PATH so that you can run it
directly at the command line.
pub global run
$ pub global run <package>:<executable> [args...]
Once you have activated a package, use
run to run a script from the package’s
You can also specify arguments. The following command
bin/bar.dart script from the
and passes in two arguments.
$ pub global run foo:bar arg1 arg2
A package may choose to expose some of its scripts as executables
that can be run directly from the command line. The script must
be listed in the
entry of the pubspec file. For example, the following pubspec file
bin/helloworld.dart as an executable for the helloworld package:
name: helloworld executables: helloworld:
When you globally activate a package using any of the
pub global activate
options, pub creates a shell script for each
entry listed in the
executables section of the pubspec,
and adds it to the
bin directory in your
For Linux and Mac, this file is located in
If you want to activate a subset of the list of executables,
-x<name>, for short).
You must manually add the pub cache
bin directory to your PATH.
If the executable’s name conflicts with a previously activated executable,
it generates a warning. To force pub to install the new executable,
--overwrite. For example:
$ pub global activate <package> --executable=<name>
You can now run
helloworld at the command line.
For more information on the these flags, see Options.
$ pub global deactivate <package>
deactivate to remove a package from the list of available
global packages. For example:
$ pub global deactivate markdown
You can no longer invoke the package’s scripts using
pub global run,
or at the command line.
$ pub global list
list to list all currently active packages.
For options that apply to all pub commands, see Global options.
pub global activate. The constraint allows you to pull in a specific version of the package. For example, the following command pulls the 0.6.0 version of the
$ pub global activate markdown 0.6.0
If you specify a range, pub picks the best version that meets that constraint. For example:
$ pub global activate foo <3.0.0
pub global activate. Adds the specified executable to your PATH. You can pass more than one of these flags. For example, the following command adds
baz(but not any other executables that
foomight define) to your PATH.
$ pub global activate foo -x bar -x baz
pub global activate. Globally activates the package but doesn’t put any executables in
bin. You have to use
pub global runto run any executables.
pub global activate. Normally, if executables from two global packages have a name collision, the preexisting executable wins. If you specify this flag, the new executable overwrites the previously activated executable.