Pub CommandsSend feedback
The pub tool has commands for managing packages, running and serving apps, and building and deploying web apps.
Quick links to the
Pub’s commands fall into the following categories:
Pub provides a number of commands that support the creation and maintenance of a Dart application.
In this group, the most commonly used commands are
pub get and
pub upgrade, which retrieve or upgrade dependencies used by a project.
Every time you modify a pubspec file, run
to make sure the dependencies are up to date. Some IDEs
perform this step automatically on the creation of a package,
or any modification of the pubspec.
- Manages pub’s local package cache. Use this command to add packages to your cache, or to perform a clean reinstall of all packages in your cache.
- Lists all dependencies used by a package.
- Retrieves the lowest versions of all the packages that are listed as dependencies used by the application. Used for testing the lower range of your package’s dependencies.
- Retrieves the packages that are listed as the dependencies for
pubspec.lockfile already exists, fetches the version of each dependency (if possible) as listed in the lock file. Creates or updates the lock file, as needed.
- Retrieves the latest version of each package listed
as dependencies used by the application. If a
pubspec.lockfile exists, ignores the versions listed in the lock file and fetches the newest versions that honor the constraints in the pubspec. Creates or updates the lock file, as needed.
Running and serving apps
Pub supports development for running web apps and command-line apps.
If your web app’s directory structure follows pub’s package layout
conventions, you can use the pub development
pub serve) to continuously
build and serve the app’s assets.
This server can be accessed via the browser on localhost and
allows you to view your web-based app.
IDEs such as WebStorm also use
pub serve to serve all of the
Dart scripts and assets (HTML, images, CSS) to the browser.
There are two commands that you can use to run Dart scripts from the command line. Each command first runs any needed transformers before invoking the specified script.
pub runcommand invokes a Dart script in your package, or in one of its dependencies.
pub globalcommand lets you work with globally available packages that can be run when you are not currently inside a package.
Building and deploying apps and packages
With pub you can publish packages, build deployable web apps, and deploy command-line apps.
To share your Dart packages with the world, you can
pub publish command to upload the
package to pub.dartlang.org. The
pub uploader command enables specific
users to modify and upload new versions of your package.
Once you’re ready to deploy a web app,
to generate the final files. This command creates the
compiles the Dart code, and places all necessary files into the build
For any package that contains scripts (anything under the
directory), consider adding the
executables tag to the pubspec file.
When a script is listed under
executables, users can run
pub global activate
to make it directly available from the command line.
Several command-line options work with all of the pub commands. These include:
- Print usage information.
- Print version of pub.
- Print debugging information when an error occurs.
- The specified level determines the amount of information that is displayed:
- Show all output, including internal tracing messages.
- Show I/O operations.
- Show errors, warnings, and user messages.
- Show steps during version resolution.
- Equivalent to