The pub package manager has a command-line interface
that works with either the
flutter tool or the
With either tool, add the
pub command followed by
a subcommand such as
$ dart pub get # Gets dependencies for a non-Flutter package $ flutter pub get # Gets dependencies for a Flutter package
This site uses
dart pub <subcommand> for its examples,
but if your current directory holds a Flutter app
or other Flutter-specific code,
flutter pub <subcommand> instead.
For more information, see
on the Flutter website.
If you encounter problems using the pub tool, see Troubleshooting Pub.
List of subcommands
Detailed documentation exists for each of the following pub subcommands:
Overview of subcommands
Pub’s subcommands fall into the following categories:
Managing package dependencies
Pub provides a number of subcommands for managing the packages your code depends on.
In this group, the most commonly used subcommands are
upgrade, which retrieve or upgrade dependencies used by a package.
Every time you modify a pubspec file,
dart pub get or
flutter pub get
to make sure the dependencies are up to date. Some IDEs
perform this step automatically on the creation of a project,
or any modification of the pubspec.
- Manages pub’s local package cache. Use this subcommand to add packages to your cache, or to perform a clean reinstall of all packages in your cache.
- Lists all dependencies used by the current package.
- Retrieves the lowest versions of all the packages that are listed as dependencies used by the current package. Used for testing the lower range of your package’s dependencies.
- Retrieves the packages that are listed as the dependencies for
the current package.
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.
- Looks at every package that the current package depends on, determines which package dependencies are out of date, and gives you advice on how to update them. Use this subcommand when you want to update package dependencies.
- Retrieves the latest version of each package listed
as dependencies used by the current package. 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 command-line apps
global subcommand lets you
make a package globally available,
so you can run scripts from that package’s
To run globally available scripts, you must
add the system cache
bin directory to your path.
Deploying packages and apps
With pub you can publish packages and command-line apps.
To share your Dart packages with the world, you can
publish subcommand to upload the
package to the pub.dev site.
For information on allowing other users
to modify and upload new versions of your package,
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
dart pub global activate
to make it directly available from the command line.
Several command-line options work with all of the pub subcommands. These include:
Prints usage information.
Prints debugging information when an error occurs.
Runs the command in the specified directory.
Adds color to the output for emphasis (
The default depends on whether you’re using this command at a terminal.
At a terminal,
--color is the default,
--no-color is the default.
--no-color to disable color in all environments.