0Pricing
Dart Academy · Lesson

Adding Dependencies With dart pub

Fetch and version external packages.

Adding Dependencies With dart pub is a free Dart Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Dart Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

The dart pub Command

The dart pub command is your package manager. It fetches, adds, and updates the external code your project relies on. 📦

Adding a Package

The fastest way to add a dependency is dart pub add. It edits pubspec.yaml for you and downloads the package in one step.

dart pub add http

What add Writes

After adding, your dependencies section gains a new line with a sensible caret constraint, so you do not have to hand-edit the file.

dependencies:
  http: ^1.2.0

Adding a Dev Dependency

Pass the --dev flag to place a package under dev_dependencies instead. Use this for test runners and other build-time tools.

dart pub add --dev test

Fetching Everything

When you clone a project, run dart pub get. It reads pubspec.yaml and downloads every listed dependency into a local cache.

dart pub get

Upgrading Packages

Use dart pub upgrade to move dependencies to the newest versions still allowed by your constraints. Existing limits are respected.

dart pub upgrade

Pinning an Exact Version

You can add a package at a specific version by appending a colon and the number. This is handy when you need a known-good release.

dart pub add http:1.1.0

Seeing Outdated Packages

Run dart pub outdated to see which dependencies have newer versions available. It shows current, upgradable, and latest columns.

dart pub outdated

Removing a Package

Changed your mind? dart pub remove deletes the entry from pubspec.yaml and cleans it out of your resolved dependencies.

dart pub remove http

Packages Come From pub.dev

By default these packages are downloaded from pub.dev, the official Dart package repository where the community publishes shared code.

The Local Cache

Downloaded packages live in a shared cache on your machine, so multiple projects reuse the same files instead of re-downloading them.

Quick Check

Which command both edits pubspec.yaml and downloads the package?

Recap

You can now add, get, upgrade, and remove packages with dart pub, all pulled from pub.dev into a shared local cache. 🎉

Frequently asked questions

Is the “Adding Dependencies With dart pub” lesson free?

Yes — the full text of “Adding Dependencies With dart pub” is free to read here on the web, and the Dart Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Dart Academy course, upgrade to CoddyKit PRO.

What will I learn in “Adding Dependencies With dart pub”?

Fetch and version external packages. You practise Dart Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Dart Academy?

No prior experience is required. Dart Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Adding Dependencies With dart pub” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Dart Academy lesson?

Yes. Every Dart Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Anatomy of pubspec.yaml
  2. Adding Dependencies With dart pub
  3. Imports, Exports, and Libraries
  4. Version Constraints and the Lockfile
← Back to Dart Academy