How to install an updated version of a Dart package?

dart, dart-pub, installation, package-managers, updates

Solution

The DartEditor calls `pub get` automatically when the file `pubspec.yaml` is updated.

You may call it manually (e.g. when you for example checked out a project from GitHub without modifying any file)

- by using the context menu `Pub Get` in DartEditor on the file `pubspec.yaml`

- by calling `pub get` on the command line in the package directory where the file `pubspec.yaml` is stored.

`pub get` downloads the package version noted in the file `pubspec.lock` (in the package root directory) or the most recent version that fulfills your version constraint (`0.0.1` in your example could be `any` for 'most recent') if `pubspec.lock` doesn't exist. `pub get`/`pub upgrade` create the file `pubspec.lock` if it doesn't yet exist and save the versions of the downloaded packages it just downloaded.

Check for updated packages and download them using

- context menu `Pub Upgrade` in DartEditor on the file `pubspec.yaml`

- `pub upgrade` on the command line in the package directory where the file `pubspec.yaml` is stored.

`pub upgrade` downloads the most recent version that fulfills your version constraints and stores the downloaded version in the file `pubspec.lock`.

`pub get`/`pub upgrade` prefers stable releases (version numbers that don't contain a `-`) like `0.0.1` or `1.2.0+1` over pre-releases like `0.0.2-1` or `1.2.1-1` if any is available that fulfulls your version constraint.

If you want a pre-release you have to tighten the version constraint so that only the pre-release fulfills your constraints (like `angular: '>=1.2.1'`)

`pub upgrade` may show an output like

analyzer 0.10.5 (9 newer versions available)

Which indicates that there are 9 prerelease builds available that are newer than the downloaded stable build.

The version constraint for your dependency needs to fulfill the version constraints of all your dependencies dependencies (E.g. if you add the dependencies `observe` and `polymer` where `polymer` depends on `observe` itself).

You can force `pub get`/`pub upgrade` to a version that violates your dependencies dependency by defining the dependency with a version constraint under `dependencies_override:` instead of `dependencies:` in `pubspec.yaml`.

You may also add `dev_dependencies` (e.g. `unittest`) which are only downloaded when they are defined in your package but ignored when they are only defined in one of your dependencies.

You see, this is an advanced topic even for seasoned Dart developers.

Problem

When a new Dart package is published, how can I install the updated version?

Original source