The pub tool

    Flutter note: If you’re using the Flutter SDK, don’t use the pub command directly. Instead use the flutter pub command, as described in on the Flutter website.

    Quick links to the pub commands:

    _Problems?_See Troubleshooting Pub.

    Pub provides a number of commands for managing thepackages your code depends on.

    In this group, the most commonly used commands are pub get andpub upgrade, which retrieve or upgrade dependencies used by a package.Every time you modify a pubspec file, run to make sure the dependencies are up to date. Some IDEsperform this step automatically on the creation of a project,or any modification of the pubspec.

    • Manages pub’s local package cache. Use this command to add packagesto your cache, or to perform a clean reinstall of all packages inyour cache.
    • pub deps
    • Lists all dependencies used by the current package.
    • Retrieves the lowest versions of all the packages that arelisted as dependencies used by the current package. Used for testingthe lower range of your package’s dependencies.
    • pub get
    • Retrieves the packages that are listed as the dependencies forthe current package.If a pubspec.lock file already exists, fetches the versionof 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 listedas dependencies used by the current package. If a pubspec.lockfile exists, ignores the versions listed in the lock file and fetchesthe newest versions that honor the constraints in the pubspec.Creates or updates the lock file, as needed.

    Two commands let you run Dart scripts from the command line:

    • The pub global command lets you work withglobally available packages.

    With pub you can publish packages and command-line apps.

    Note: Pub used to support building apps through commands like pub build and pub serve. That functionality is now in other tools such as the build system. For details, see .

    To share your Dart packages with the world, you canuse the pub publish command to upload thepackage to the . Thepub uploader command enables specificusers to modify and upload new versions of your package.

    Command-line apps


    Several command-line options work with all of the pub commands.These include:

    • —help or -h
    • Print usage information.
    • —version
    • —trace
    • Print debugging information when an error occurs.
    • —verbosity=<level>
    • The specified level determines the amount of information that is displayed:
      • all
      • Show all output, including internal tracing messages.
      • io
      • Show I/O operations.
      • normal
      • Show errors, warnings, and user messages.
      • solver
      • Show steps during version resolution.
    • Equivalent to —verbosity=all.